Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize parse and render options #145

Merged
merged 4 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,31 @@ CommonMarker accepts the same options that CMark does, as symbols. Note that the
| Name | Description
| ----------------------------- | -----------
| `:DEFAULT` | The default parsing system.
| `:SOURCEPOS` | Include source position in nodes
| `:UNSAFE` | Allow raw/custom HTML and unsafe links.
| `:FOOTNOTES` | Parse footnotes.
| `:LIBERAL_HTML_TAG` | Support liberal parsing of inline HTML tags.
| `:VALIDATE_UTF8` | Replace illegal sequences with the replacement character `U+FFFD`.
| `:SMART` | Use smart punctuation (curly quotes, etc.).
| `:LIBERAL_HTML_TAG` | Support liberal parsing of inline HTML tags.
| `:FOOTNOTES` | Parse footnotes.
| `:STRIKETHROUGH_DOUBLE_TILDE` | Parse strikethroughs by double tildes (compatibility with [redcarpet](https://github.com/vmg/redcarpet))
| `:VALIDATE_UTF8` | Replace illegal sequences with the replacement character `U+FFFD`.

### 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. |
| `:SOURCEPOS` | Include source position in rendered HTML. |
| `:HARDBREAKS` | Treat `\n` as hardbreaks (by adding `<br/>`). |
| `:UNSAFE` | Allow raw/custom HTML and unsafe links. |
| `:NOBREAKS` | Translate `\n` in the source to a single whitespace. |
| `:SOURCEPOS` | Include source position in rendered HTML. |
| `:VALIDATE_UTF8` | Replace illegal sequences with the replacement character `U+FFFD`. |
| `:SMART` | Use smart punctuation (curly quotes, etc.). |
| `:GITHUB_PRE_LANG` | Use GitHub-style `<pre lang>` for fenced code blocks. |
| `:LIBERAL_HTML_TAG` | Support liberal parsing of inline HTML tags. |
| `:FOOTNOTES` | Render footnotes. |
| `:STRIKETHROUGH_DOUBLE_TILDE` | Parse strikethroughs by double tildes (compatibility with [redcarpet](https://github.com/vmg/redcarpet)) |
| `: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
11 changes: 8 additions & 3 deletions lib/commonmarker/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,28 @@ module Config
OPTS = {
parse: {
DEFAULT: 0,
SOURCEPOS: (1 << 1),
Copy link
Collaborator Author

@phillmv phillmv Aug 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NEW parse option:

As far as I can tell, we check for SOURCEPOS in inlines.c, and if the flag is set we annotate the node with sourcepos info, thereby allowing someone implementing their own renderer to also add sourcepos info to their output.

UNSAFE: (1 << 17)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep it inline with the deprecated SAFE flag, cmark-gfm.h defines UNSAFE after 1 << 3, so I've sorted it here accordingly.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a comma is missing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦

VALIDATE_UTF8: (1 << 9),
SMART: (1 << 10),
LIBERAL_HTML_TAG: (1 << 12),
FOOTNOTES: (1 << 13),
STRIKETHROUGH_DOUBLE_TILDE: (1 << 14),
UNSAFE: (1 << 17)
}.freeze,
render: {
DEFAULT: 0,
SOURCEPOS: (1 << 1),
HARDBREAKS: (1 << 2),
UNSAFE: (1 << 17),
NOBREAKS: (1 << 4),
VALIDATE_UTF8: (1 << 9),
Copy link
Collaborator Author

@phillmv phillmv Aug 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied over all of the parse options and resorted the render hash. As described in the PR description, since the render method also initializes the parser with the same options integer, all of the parse options should be available as render options as well.

SMART: (1 << 10),
GITHUB_PRE_LANG: (1 << 11),
LIBERAL_HTML_TAG: (1 << 12),
FOOTNOTES: (1 << 13)
STRIKETHROUGH_DOUBLE_TILDE: (1 << 14),
TABLE_PREFER_STYLE_ATTRIBUTES: (1 << 15),
FULL_INFO_STRING: (1 << 16),
UNSAFE: (1 << 17),
FOOTNOTES: (1 << 13)
}.freeze,
format: %i[html xml commonmark plaintext].freeze
}.freeze
Expand Down