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

Extend namedCodesToUnicode with own/specific html codes #236

Closed
tangleMesh opened this issue Feb 27, 2019 · 1 comment · Fixed by #253
Closed

Extend namedCodesToUnicode with own/specific html codes #236

tangleMesh opened this issue Feb 27, 2019 · 1 comment · Fixed by #253

Comments

@tangleMesh
Copy link
Contributor

tangleMesh commented Feb 27, 2019

Would it be possible to extend the namedCodesToUnicode constant with custom html codes to display them correctly.

Therefore a new options.namedCodesToUnicode object could integrated to extend the existing constant list while keeping the list in this repository as small/clean as it is at the moment.

options.namedCodesToUnicode = options.namedCodesToUnicode ? {...namedCodesToUnicode, ...options.namedCodesToUnicode} : namedCodesToUnicode;
…
.replace(HTML_CHAR_CODE_R, (full, inner) => {
              return options.namedCodesToUnicode[inner]
                ? options.namedCodesToUnicode[inner]
                : full;
            }),
…

The documentation could also be extended and the new options could work like this:

options.namedCodesToUnicode

By default only a couple of named html codes are converted to unicode characters.

  • & (&)
  • ' (')
  • > (>)
  • < (&lt;)
  • (&nbsp;)
  • " (&quot;)

Some projects require to extend this map of named codes and unicode characters. To customize this list with additional html codes pass the option namedCodesToUnicode as object with the code names needed as in the example below:

<Markdown options={{ namedCodesToUnicode: {
    le: '\u2264',
    ge: '\u2265',
} }}>This text is &le; than this text.</Markdown>;

// or

compiler('This text is &le; than this text.', namedCodesToUnicode: {
    le: '\u2264',
    ge: '\u2265',
});

// renders:

<p>This text is ≤ than this text.</p>
@quantizor
Copy link
Owner

Hmm yeah that seems reasonable if you'd like to send a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants