Skip to content

Commit

Permalink
feat(compiler): allow replacing of special capital html characters (#448
Browse files Browse the repository at this point in the history
)
  • Loading branch information
garywilddev authored Jan 31, 2023
1 parent 474301d commit ebd044a
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
83 changes: 83 additions & 0 deletions index.compiler.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3147,6 +3147,89 @@ describe('footnotes', () => {
})
})

describe('options.namedCodesToUnicode', () => {
// & > < are already replaced by default
const content =
'Æ,Á,Â,À,Å,Ã,Ä,Ç,É,Ê,È,Ë,Í,Î,Ì,Ï,Ñ,Ó,Ô,Ò,Ø,Õ,Ö,Ú,Û,Ù,Ü,Ý,á,â,æ,à,å,ã,ä,ç,&coy;,é,ê,è,ë,≥,í,î,ì,ï,«,≤, ,ñ,ó,ô,ò,ø,õ,ö,¶,",»,ß,ú,û,ù,ü,ý'

const namedCodesToUnicode = {
AElig: 'Æ',
Aacute: 'Á',
Acirc: 'Â',
Agrave: 'À',
Aring: 'Å',
Atilde: 'Ã',
Auml: 'Ä',
Ccedil: 'Ç',
Eacute: 'É',
Ecirc: 'Ê',
Egrave: 'È',
Euml: 'Ë',
Iacute: 'Í',
Icirc: 'Î',
Igrave: 'Ì',
Iuml: 'Ï',
Ntilde: 'Ñ',
Oacute: 'Ó',
Ocirc: 'Ô',
Ograve: 'Ò',
Oslash: 'Ø',
Otilde: 'Õ',
Ouml: 'Ö',
Uacute: 'Ú',
Ucirc: 'Û',
Ugrave: 'Ù',
Uuml: 'Ü',
Yacute: 'Ý',
aacute: 'á',
acirc: 'â',
aelig: 'æ',
agrave: 'à',
aring: 'å',
atilde: 'ã',
auml: 'ä',
ccedil: 'ç',
coy: '©',
eacute: 'é',
ecirc: 'ê',
egrave: 'è',
euml: 'ë',
ge: '\u2265',
iacute: 'í',
icirc: 'î',
igrave: 'ì',
iuml: 'ï',
laquo: '«',
le: '\u2264',
nbsp: ' ',
ntilde: 'ñ',
oacute: 'ó',
ocirc: 'ô',
ograve: 'ò',
oslash: 'ø',
otilde: 'õ',
ouml: 'ö',
para: '§',
quot: '"',
raquo: '»',
szlig: 'ß',
uacute: 'ú',
ucirc: 'û',
ugrave: 'ù',
uuml: 'ü',
yacute: 'ý',
}

it('should replace special HTML characters', () => {
render(compiler(content, { namedCodesToUnicode }))
expect(root.innerHTML).toMatchInlineSnapshot(`
<span>
Æ,Á,Â,À,Å,Ã,Ä,Ç,É,Ê,È,Ë,Í,Î,Ì,Ï,Ñ,Ó,Ô,Ò,Ø,Õ,Ö,Ú,Û,Ù,Ü,Ý,á,â,æ,à,å,ã,ä,ç,©,é,ê,è,ë,≥,í,î,ì,ï,«,≤, ,ñ,ó,ô,ò,ø,õ,ö,§,",»,ß,ú,û,ù,ü,ý
</span>
`)
})
})

describe('options.forceBlock', () => {
it('treats given markdown as block-context', () => {
render(
Expand Down
2 changes: 1 addition & 1 deletion index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ const HEADING_SETEXT_R = /^([^\n]+)\n *(=|-){3,} *(?:\n *)+\n/
const HTML_BLOCK_ELEMENT_R =
/^ *(?!<[a-z][^ >/]* ?\/>)<([a-z][^ >/]*) ?([^>]*)\/{0}>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1)[\s\S])*?)<\/\1>\n*/i

const HTML_CHAR_CODE_R = /&([a-z]+);/g
const HTML_CHAR_CODE_R = /&([a-zA-Z]+);/g

const HTML_COMMENT_R = /^<!--[\s\S]*?(?:-->)/

Expand Down

0 comments on commit ebd044a

Please sign in to comment.