Skip to content

Commit

Permalink
Merge pull request #131 from aharpole/footnotes-render-option
Browse files Browse the repository at this point in the history
Support :FOOTNOTES option for rendering HTML
  • Loading branch information
kivikakk authored Feb 11, 2021
2 parents 65d0b15 + 12af5f6 commit fa9528a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,17 @@ CommonMarker accepts the same options that CMark does, as symbols. Note that the

### Render options

| Name | Description |
| ------------------ | ----------- |
| `:DEFAULT` | The default rendering system. |
| `:UNSAFE` | Allow raw/custom HTML and unsafe links. |
| `:GITHUB_PRE_LANG` | Use GitHub-style `<pre lang>` for fenced code blocks. |
| `:HARDBREAKS` | Treat `\n` as hardbreaks (by adding `<br/>`). |
| `:NOBREAKS` | Translate `\n` in the source to a single whitespace. |
| `:SOURCEPOS` | Include source position in rendered HTML. |
| `:TABLE_PREFER_STYLE_ATTRIBUTES` | Use `style` insted of `align` for table cells |
| `:FULL_INFO_STRING` | Include full info strings of code blocks in separate attribute |
| Name | Description |
| ------------------ | ----------- |
| `:DEFAULT` | The default rendering system. |
| `:UNSAFE` | Allow raw/custom HTML and unsafe links. |
| `:GITHUB_PRE_LANG` | Use GitHub-style `<pre lang>` for fenced code blocks. |
| `:HARDBREAKS` | Treat `\n` as hardbreaks (by adding `<br/>`). |
| `:NOBREAKS` | Translate `\n` in the source to a single whitespace. |
| `:SOURCEPOS` | Include source position in rendered HTML. |
| `:TABLE_PREFER_STYLE_ATTRIBUTES` | Use `style` insted of `align` for table cells. |
| `:FULL_INFO_STRING` | Include full info strings of code blocks in separate attribute. |
| `:FOOTNOTES` | Render footnotes. |

### Passing options

Expand Down
1 change: 1 addition & 0 deletions lib/commonmarker/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Render
define :TABLE_PREFER_STYLE_ATTRIBUTES, (1 << 15)
define :FULL_INFO_STRING, (1 << 16)
define :UNSAFE, (1 << 17)
define :FOOTNOTES, (1 << 13)
end

def self.process_options(option, type)
Expand Down
21 changes: 21 additions & 0 deletions test/test_footnotes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,25 @@ def test_to_html
def test_html_renderer
assert_equal @expected, CommonMarker::HtmlRenderer.new.render(@doc)
end

def test_render_html
md = <<~MARKDOWN
# footnotes
Let's render some footnotes[^1]
[^1]: This is a footnote
MARKDOWN
expected = <<~HTML
<h1>footnotes</h1>
<p>Let's render some footnotes<sup class="footnote-ref"><a href="#fn1" id="fnref1">1</a></sup></p>
<section class="footnotes">
<ol>
<li id="fn1">
<p>This is a footnote <a href="#fnref1" class="footnote-backref"></a></p>
</li>
</ol>
</section>
HTML
assert_equal expected, CommonMarker.render_html(md, :FOOTNOTES)
end
end

0 comments on commit fa9528a

Please sign in to comment.