@tinymce/moxiedoc
Advanced tools
Comparing version 0.2.0-feature.20220319035257520.shaac589ca to 0.2.0-feature.20220326065652519.shac1bbb7f
@@ -22,6 +22,6 @@ "use strict"; | ||
const encodeBR = (str) => str.replace(/<br\s*\/?>/g, '\n'); | ||
// convert <em> into _italics_ asciidoc | ||
const encodeEM = (str) => str.replace(/<\/?em>/g, '_'); | ||
// convert <strong> into *bold* asciidoc | ||
const encodeStrong = (str) => str.replace(/<\/?strong>/g, '*'); | ||
// convert <em> into __italics__ asciidoc | ||
const encodeEM = (str) => str.replace(/<\/?em>/g, '__'); | ||
// convert <strong> into **bold** asciidoc | ||
const encodeStrong = (str) => str.replace(/<\/?strong>/g, '**'); | ||
// convert <code> into backtick asciidoc | ||
@@ -47,7 +47,16 @@ const encodeCode = (str) => { | ||
}; | ||
// escape special asciidoc characters | ||
const specialChars = { | ||
'|': '{vbar}', | ||
'+': '{plus}', | ||
'*': '{asterisk}' | ||
}; | ||
const escapeSpecialChars = (str) => str.replace(/[|+*]/g, (match) => specialChars[match] || match); | ||
// convert content that looks like asciidoc attributes (e.g {0}) to literal strings | ||
const escapeAttributes = (str) => str.replace(/(\{\s*[\w\d-]+\s*\})/g, '+$1+'); | ||
// Note: Special characters should not be escaped | ||
const specialAttrs = Object.values(specialChars); | ||
const escapeAttributes = (str) => str.replace(/(\{\s*[\w\d-]+\s*\})/g, (match) => specialAttrs.indexOf(match) !== -1 ? match : `+${match}+`); | ||
// runs a bunch of required cleanup filters, where embedded code/text can break asciidoc rendering | ||
const cleanup = (str) => { | ||
const filters = [escapeComments, encodeBR, encodeEM, encodeStrong, encodeLinks, encodeCode, escapeAttributes]; | ||
const filters = [escapeSpecialChars, escapeAttributes, escapeComments, encodeBR, encodeEM, encodeStrong, encodeLinks, encodeCode]; | ||
return filters.reduce((acc, filter) => filter(acc), str); | ||
@@ -54,0 +63,0 @@ }; |
{ | ||
"name": "@tinymce/moxiedoc", | ||
"version": "0.2.0-feature.20220319035257520.shaac589ca", | ||
"version": "0.2.0-feature.20220326065652519.shac1bbb7f", | ||
"description": "A tool for generating API documentation", | ||
@@ -5,0 +5,0 @@ "author": "Tiny Technologies, Inc", |
@@ -32,9 +32,9 @@ import { Return } from '../../lib/member'; | ||
// convert <em> into _italics_ asciidoc | ||
// convert <em> into __italics__ asciidoc | ||
const encodeEM = (str: string): string => | ||
str.replace(/<\/?em>/g, '_'); | ||
str.replace(/<\/?em>/g, '__'); | ||
// convert <strong> into *bold* asciidoc | ||
// convert <strong> into **bold** asciidoc | ||
const encodeStrong = (str: string): string => | ||
str.replace(/<\/?strong>/g, '*'); | ||
str.replace(/<\/?strong>/g, '**'); | ||
@@ -62,9 +62,20 @@ // convert <code> into backtick asciidoc | ||
// escape special asciidoc characters | ||
const specialChars = { | ||
'|': '{vbar}', | ||
'+': '{plus}', | ||
'*': '{asterisk}' | ||
}; | ||
const escapeSpecialChars = (str: string): string => | ||
str.replace(/[|+*]/g, (match) => specialChars[match] || match); | ||
// convert content that looks like asciidoc attributes (e.g {0}) to literal strings | ||
// Note: Special characters should not be escaped | ||
const specialAttrs = Object.values(specialChars); | ||
const escapeAttributes = (str: string): string => | ||
str.replace(/(\{\s*[\w\d-]+\s*\})/g, '+$1+'); | ||
str.replace(/(\{\s*[\w\d-]+\s*\})/g, (match) => specialAttrs.indexOf(match) !== -1 ? match : `+${match}+`); | ||
// runs a bunch of required cleanup filters, where embedded code/text can break asciidoc rendering | ||
const cleanup = (str: string): string => { | ||
const filters = [ escapeComments, encodeBR, encodeEM, encodeStrong, encodeLinks, encodeCode, escapeAttributes ]; | ||
const filters = [ escapeSpecialChars, escapeAttributes, escapeComments, encodeBR, encodeEM, encodeStrong, encodeLinks, encodeCode ]; | ||
return filters.reduce((acc, filter) => filter(acc), str); | ||
@@ -71,0 +82,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
345567
6676