Koenig icon indicating copy to clipboard operation
Koenig copied to clipboard

Add support for line numbers in Markdown code fences

Open coreyasmith opened this issue 1 year ago • 1 comments

Older versions of Ghost (2 and earlier?) used to support line numbers in Markdown code fences by adding line-numbers after the language:

```ruby line-numbers
foo = "bar"
```

This would be rendered as:

<pre>
  <code class="line-numbers language-ruby">
  foo = "bar"
  </code>
</pre>

The Prism Line Numbers plugin would then render line numbers for that code block.

This pull request adds in a markdown-it plugin that I implemented called markdown-it-fence-line-numbers to restore this functionality to Ghost's Markdown cards.

coreyasmith avatar Oct 09 '24 19:10 coreyasmith

Walkthrough

The PR adds a new function fenceLineNumbers(md) that augments fenced code rendering by detecting the line-numbers token in a fence's info string and appending the line-numbers class when present, otherwise delegating to the default fence renderer. selectRenderer is updated to apply this plugin for the latest Ghost renderer path (4.x+). Tests were added to assert that fenced blocks include class="line-numbers language-..." when requested and remain class="language-..." otherwise; behavior for Ghost <4.x is unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly and accurately describes the primary change introduced by the pull request, namely adding support for line numbers in Markdown code fences, and is fully aligned with the code modifications and objectives.
Description Check ✅ Passed The description clearly explains the previous behavior, the motivation for restoring line-number support, and how the new markdown-it plugin implementation achieves this, directly reflecting the changes in the PR.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • [ ] 📝 Generate Docstrings
🧪 Generate unit tests
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

[!TIP]

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Feb 18 '25 01:02 coderabbitai[bot]

Codecov Report

:x: Patch coverage is 87.09677% with 4 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 90.88%. Comparing base (8c3fc1c) to head (733f4ef). :warning: Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...rkdown-html-renderer/lib/markdown-html-renderer.js 87.09% 4 Missing :warning:
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1381   +/-   ##
=======================================
  Coverage   90.87%   90.88%           
=======================================
  Files         188      188           
  Lines       17887    17917   +30     
  Branches     2000     2006    +6     
=======================================
+ Hits        16254    16283   +29     
- Misses       1622     1623    +1     
  Partials       11       11           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov-commenter avatar Sep 26 '25 01:09 codecov-commenter