run npm install to generate a package lock
This commit is contained in:
21
node_modules/marked-smartypants/LICENSE
generated
vendored
Normal file
21
node_modules/marked-smartypants/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 @markedjs
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
24
node_modules/marked-smartypants/README.md
generated
vendored
Normal file
24
node_modules/marked-smartypants/README.md
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# marked-smartypants
|
||||
|
||||
Use [smartypants](https://www.npmjs.com/package/smartypants) to easily translate plain ASCII punctuation characters into "smart" typographic punctuation HTML entities.
|
||||
|
||||
# Usage
|
||||
|
||||
```js
|
||||
import { marked } from "marked";
|
||||
import { markedSmartypants } from "marked-smartypants";
|
||||
|
||||
// or UMD script
|
||||
// <script src="https://cdn.jsdelivr.net/npm/marked/lib/marked.umd.js"></script>
|
||||
// <script src="https://cdn.jsdelivr.net/npm/marked-smartypants/lib/index.umd.js"></script>
|
||||
|
||||
marked.use(markedSmartypants());
|
||||
|
||||
// or optionally provide smartpants configuration
|
||||
// marked.use(markedSmartypants({ config: "1" }));
|
||||
|
||||
marked.parse("He said, -- \"A 'simple' sentence. . .\" --- unknown");
|
||||
// <p>He said, – “A ‘simple’ sentence…” — unknown</p>
|
||||
```
|
||||
|
||||
Information on available smartypants configurations is available [here](https://github.com/othree/smartypants.js#options-and-configuration).
|
||||
473
node_modules/marked-smartypants/lib/index.cjs
generated
vendored
Normal file
473
node_modules/marked-smartypants/lib/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,473 @@
|
||||
'use strict';
|
||||
|
||||
const tags_to_skip = /<(\/?)(?:pre|code|kbd|script|math)[^>]*>/i;
|
||||
/**
|
||||
* @param text text to be parsed
|
||||
* @param attr value of the smart_quotes="" attribute
|
||||
*/
|
||||
const SmartyPants = (text = '', attr = '1') => {
|
||||
var do_quotes;
|
||||
var do_backticks;
|
||||
var do_dashes;
|
||||
var do_ellipses;
|
||||
var do_stupefy;
|
||||
var convert_quot = 0;
|
||||
if (typeof attr === 'number') {
|
||||
attr = attr.toString();
|
||||
}
|
||||
else {
|
||||
attr = attr.replace(/\s/g, '');
|
||||
}
|
||||
/**
|
||||
* Parse attributes:
|
||||
* 0 : do nothing
|
||||
* 1 : set all
|
||||
* 2 : set all, using old school en- and em- dash shortcuts
|
||||
* 3 : set all, using inverted old school en and em- dash shortcuts
|
||||
*
|
||||
* q : quotes
|
||||
* b : backtick quotes (``double'' only)
|
||||
* B : backtick quotes (``double'' and `single')
|
||||
* d : dashes
|
||||
* D : old school dashes
|
||||
* i : inverted old school dashes
|
||||
* e : ellipses
|
||||
* w : convert " entities to " for Dreamweaver users
|
||||
*/
|
||||
if (attr === '0') {
|
||||
// Do nothing
|
||||
return text;
|
||||
}
|
||||
else if (attr === '1') {
|
||||
// Do everything, turn all options on.
|
||||
do_quotes = 1;
|
||||
do_backticks = 1;
|
||||
do_dashes = 1;
|
||||
do_ellipses = 1;
|
||||
}
|
||||
else if (attr === '2') {
|
||||
// Do everything, turn all options on, use old school dash shorthand.
|
||||
do_quotes = 1;
|
||||
do_backticks = 1;
|
||||
do_dashes = 2;
|
||||
do_ellipses = 1;
|
||||
}
|
||||
else if (attr === '3') {
|
||||
// Do everything, turn all options on, use inverted old school dash shorthand.
|
||||
do_quotes = 1;
|
||||
do_backticks = 1;
|
||||
do_dashes = 3;
|
||||
do_ellipses = 1;
|
||||
}
|
||||
else if (attr === '-1') {
|
||||
// Special "stupefy" mode.
|
||||
do_stupefy = 1;
|
||||
}
|
||||
else {
|
||||
for (let i = 0; i < attr.length; i++) {
|
||||
let c = attr[i];
|
||||
if (c === 'q') {
|
||||
do_quotes = 1;
|
||||
}
|
||||
if (c === 'b') {
|
||||
do_backticks = 1;
|
||||
}
|
||||
if (c === 'B') {
|
||||
do_backticks = 2;
|
||||
}
|
||||
if (c === 'd') {
|
||||
do_dashes = 1;
|
||||
}
|
||||
if (c === 'D') {
|
||||
do_dashes = 2;
|
||||
}
|
||||
if (c === 'i') {
|
||||
do_dashes = 3;
|
||||
}
|
||||
if (c === 'e') {
|
||||
do_ellipses = 1;
|
||||
}
|
||||
if (c === 'w') {
|
||||
convert_quot = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
var tokens = _tokenize(text);
|
||||
var result = '';
|
||||
/**
|
||||
* Keep track of when we're inside <pre> or <code> tags.
|
||||
*/
|
||||
var in_pre = 0;
|
||||
/**
|
||||
* This is a cheat, used to get some context
|
||||
* for one-character tokens that consist of
|
||||
* just a quote char. What we do is remember
|
||||
* the last character of the previous text
|
||||
* token, to use as context to curl single-
|
||||
* character quote tokens correctly.
|
||||
*/
|
||||
var prev_token_last_char = '';
|
||||
for (let i = 0; i < tokens.length; i++) {
|
||||
let cur_token = tokens[i];
|
||||
if (cur_token[0] === 'tag') {
|
||||
result = result + cur_token[1];
|
||||
let matched = tags_to_skip.exec(cur_token[1]);
|
||||
if (matched) {
|
||||
if (matched[1] === '/') {
|
||||
in_pre = 0;
|
||||
}
|
||||
else {
|
||||
in_pre = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
let t = cur_token[1];
|
||||
let last_char = t.substring(t.length - 1, t.length); // Remember last char of this token before processing.
|
||||
if (!in_pre) {
|
||||
t = ProcessEscapes(t);
|
||||
if (convert_quot) {
|
||||
t = t.replace(/$quot;/g, '"');
|
||||
}
|
||||
if (do_dashes) {
|
||||
if (do_dashes === 1) {
|
||||
t = EducateDashes(t);
|
||||
}
|
||||
if (do_dashes === 2) {
|
||||
t = EducateDashesOldSchool(t);
|
||||
}
|
||||
if (do_dashes === 3) {
|
||||
t = EducateDashesOldSchoolInverted(t);
|
||||
}
|
||||
}
|
||||
if (do_ellipses) {
|
||||
t = EducateEllipses(t);
|
||||
}
|
||||
// Note: backticks need to be processed before quotes.
|
||||
if (do_backticks) {
|
||||
t = EducateBackticks(t);
|
||||
if (do_backticks === 2) {
|
||||
t = EducateSingleBackticks(t);
|
||||
}
|
||||
}
|
||||
if (do_quotes) {
|
||||
if (t === '\'') {
|
||||
// Special case: single-character ' token
|
||||
if (/\S/.test(prev_token_last_char)) {
|
||||
t = '’';
|
||||
}
|
||||
else {
|
||||
t = '‘';
|
||||
}
|
||||
}
|
||||
else if (t === '"') {
|
||||
// Special case: single-character " token
|
||||
if (/\S/.test(prev_token_last_char)) {
|
||||
t = '”';
|
||||
}
|
||||
else {
|
||||
t = '“';
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Normal case:
|
||||
t = EducateQuotes(t);
|
||||
}
|
||||
}
|
||||
if (do_stupefy) {
|
||||
t = StupefyEntities(t);
|
||||
}
|
||||
}
|
||||
prev_token_last_char = last_char;
|
||||
result = result + t;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with "educated" curly quote HTML entities.
|
||||
*
|
||||
* Example input: "Isn't this fun?"
|
||||
* Example output: “Isn’t this fun?”
|
||||
*/
|
||||
const EducateQuotes = (str) => {
|
||||
/**
|
||||
* Make our own "punctuation" character class, because the POSIX-style
|
||||
* [:PUNCT:] is only available in Perl 5.6 or later:
|
||||
*
|
||||
* JavaScript don't have punctuation class neither.
|
||||
*/
|
||||
var punct_class = '[!"#\$\%\'()*+,-./:;<=>?\@\[\\\]\^_`{|}~]'; // eslint-disable-line no-useless-escape
|
||||
/**
|
||||
* Special case if the very first character is a quote
|
||||
* followed by punctuation at a non-word-break. Close the quotes by brute force:
|
||||
*/
|
||||
str = str.replace(new RegExp(`^'(?=${punct_class}\\B)`), '’'); // eslint-disable-line no-useless-escape
|
||||
str = str.replace(new RegExp(`^"(?=${punct_class}\\B)`), '”'); // eslint-disable-line no-useless-escape
|
||||
/**
|
||||
* Special case for double sets of quotes, e.g.:
|
||||
* <p>He said, "'Quoted' words in a larger quote."</p>
|
||||
*/
|
||||
str = str.replace(/"'(?=\w)/, '“‘');
|
||||
str = str.replace(/'"(?=\w)/, '‘“');
|
||||
/**
|
||||
* Special case for decade abbreviations (the '80s):
|
||||
*/
|
||||
str = str.replace(/'(?=\d\d)/, '’');
|
||||
var close_class = '[^\\ \\t\\r\\n\\[\\{\\(\\-]'; // eslint-disable-line no-useless-escape
|
||||
var not_close_class = '[\\ \\t\\r\\n\\[\\{\\(\\-]'; // eslint-disable-line no-useless-escape
|
||||
var dec_dashes = '–|—';
|
||||
/**
|
||||
* Get most opening single quotes:
|
||||
* s {
|
||||
* (
|
||||
* \s | # a whitespace char, or
|
||||
* | # a non-breaking space entity, or
|
||||
* -- | # dashes, or
|
||||
* &[mn]dash; | # named dash entities
|
||||
* $dec_dashes | # or decimal entities
|
||||
* &\#x201[34]; # or hex
|
||||
* )
|
||||
* ' # the quote
|
||||
* (?=\w) # followed by a word character
|
||||
* } {$1‘}xg;
|
||||
*/
|
||||
str = str.replace(new RegExp(`(\\s| |--|&[mn]dash;|${dec_dashes}|ȁ[34])'(?=\\w)`, 'g'), '\$1‘'); // eslint-disable-line no-useless-escape
|
||||
/**
|
||||
* Single closing quotes:
|
||||
* s {
|
||||
* ($close_class)?
|
||||
* '
|
||||
* (?(1)| # If $1 captured, then do nothing;
|
||||
* (?=\s | s\b) # otherwise, positive lookahead for a whitespace
|
||||
* ) # char or an 's' at a word ending position. This
|
||||
* # is a special case to handle something like:
|
||||
* # "<i>Custer</i>'s Last Stand."
|
||||
* } {$1’}xgi;
|
||||
*/
|
||||
str = str.replace(new RegExp(`(${close_class})'`, 'g'), '\$1’'); // eslint-disable-line no-useless-escape
|
||||
str = str.replace(new RegExp(`(${not_close_class}?)'(?=\\s|s\\b)`, 'g'), '\$1’'); // eslint-disable-line no-useless-escape
|
||||
/**
|
||||
* Any remaining single quotes should be opening ones:
|
||||
*/
|
||||
str = str.replace(/'/g, '‘');
|
||||
/**
|
||||
* Get most opening double quotes:
|
||||
* s {
|
||||
* (
|
||||
* \s | # a whitespace char, or
|
||||
* | # a non-breaking space entity, or
|
||||
* -- | # dashes, or
|
||||
* &[mn]dash; | # named dash entities
|
||||
* $dec_dashes | # or decimal entities
|
||||
* &\#x201[34]; # or hex
|
||||
* )
|
||||
* " # the quote
|
||||
* (?=\w) # followed by a word character
|
||||
* } {$1“}xg;
|
||||
*/
|
||||
str = str.replace(new RegExp(`(\\s| |--|&[mn]dash;|${dec_dashes}|ȁ[34])"(?=\\w)`, 'g'), '\$1“'); // eslint-disable-line no-useless-escape
|
||||
/**
|
||||
* Double closing quotes:
|
||||
* s {
|
||||
* ($close_class)?
|
||||
* "
|
||||
* (?(1)|(?=\s)) # If $1 captured, then do nothing;
|
||||
* # if not, then make sure the next char is whitespace.
|
||||
* } {$1”}xg;
|
||||
*/
|
||||
str = str.replace(new RegExp(`(${close_class})"`, 'g'), '\$1”'); // eslint-disable-line no-useless-escape
|
||||
str = str.replace(new RegExp(`(${not_close_class}?)"(?=\\s)`, 'g'), '\$1”'); // eslint-disable-line no-useless-escape
|
||||
/**
|
||||
* Any remaining quotes should be opening ones.
|
||||
*/
|
||||
str = str.replace(/"/g, '“');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with ``backticks'' -style double quotes
|
||||
* translated into HTML curly quote entities.
|
||||
*
|
||||
* Example input: ``Isn't this fun?''
|
||||
* Example output: “Isn't this fun?”
|
||||
*/
|
||||
const EducateBackticks = (str) => {
|
||||
str = str.replace(/``/g, '“');
|
||||
str = str.replace(/''/g, '”');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with `backticks' -style single quotes
|
||||
* translated into HTML curly quote entities.
|
||||
*
|
||||
* Example input: `Isn't this fun?'
|
||||
* Example output: ‘Isn’t this fun?’
|
||||
*/
|
||||
const EducateSingleBackticks = (str) => {
|
||||
str = str.replace(/`/g, '‘');
|
||||
str = str.replace(/'/g, '’');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with each instance of "--" translated to
|
||||
* an em-dash HTML entity.
|
||||
*/
|
||||
const EducateDashes = (str) => {
|
||||
str = str.replace(/--/g, '—');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with each instance of "--" translated to
|
||||
* an en-dash HTML entity, and each "---" translated to
|
||||
* an em-dash HTML entity.
|
||||
*/
|
||||
const EducateDashesOldSchool = (str) => {
|
||||
str = str.replace(/---/g, '—');
|
||||
str = str.replace(/--/g, '–');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with each instance of "--" translated to
|
||||
* an em-dash HTML entity, and each "---" translated to
|
||||
* an en-dash HTML entity. Two reasons why: First, unlike the
|
||||
* en- and em-dash syntax supported by
|
||||
* EducateDashesOldSchool(), it's compatible with existing
|
||||
* entries written before SmartyPants 1.1, back when "--" was
|
||||
* only used for em-dashes. Second, em-dashes are more
|
||||
* common than en-dashes, and so it sort of makes sense that
|
||||
* the shortcut should be shorter to type. (Thanks to Aaron
|
||||
* Swartz for the idea.)
|
||||
*/
|
||||
const EducateDashesOldSchoolInverted = (str) => {
|
||||
str = str.replace(/---/g, '–');
|
||||
str = str.replace(/--/g, '—');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with each instance of "..." translated to
|
||||
* an ellipsis HTML entity. Also converts the case where
|
||||
* there are spaces between the dots.
|
||||
*
|
||||
* Example input: Huh...?
|
||||
* Example output: Huh…?
|
||||
*/
|
||||
const EducateEllipses = (str) => {
|
||||
str = str.replace(/\.\.\./g, '…');
|
||||
str = str.replace(/\. \. \./g, '…');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with each SmartyPants HTML entity translated to
|
||||
* its ASCII counterpart.
|
||||
*
|
||||
* Example input: “Hello — world.”
|
||||
* Example output: "Hello -- world."
|
||||
*/
|
||||
const StupefyEntities = (str) => {
|
||||
str = str.replace(/–/g, '-'); // en-dash
|
||||
str = str.replace(/—/g, '--'); // em-dash
|
||||
str = str.replace(/‘/g, '\''); // open single quote
|
||||
str = str.replace(/’/g, '\''); // close single quote
|
||||
str = str.replace(/“/g, '"'); // open double quote
|
||||
str = str.replace(/”/g, '"'); // close double quote
|
||||
str = str.replace(/…/g, '...'); // ellipsis
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} string, with after processing the following backslash
|
||||
* escape sequences. This is useful if you want to force a "dumb"
|
||||
* quote or other character to appear.
|
||||
*
|
||||
* Escape Value
|
||||
* ------ -----
|
||||
* \\ \
|
||||
* \" "
|
||||
* \' '
|
||||
* \. .
|
||||
* \- -
|
||||
* \` `
|
||||
*
|
||||
*/
|
||||
const ProcessEscapes = (str) => {
|
||||
str = str.replace(/\\\\/g, '\');
|
||||
str = str.replace(/\\"/g, '"');
|
||||
str = str.replace(/\\'/g, ''');
|
||||
str = str.replace(/\\\./g, '.');
|
||||
str = str.replace(/\\-/g, '-');
|
||||
str = str.replace(/\\`/g, '`');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String containing HTML markup.
|
||||
* @return {Array<token>} Reference to an array of the tokens comprising the input
|
||||
* string. Each token is either a tag (possibly with nested,
|
||||
* tags contained therein, such as <a href="<MTFoo>">, or a
|
||||
* run of text between tags. Each element of the array is a
|
||||
* two-element array; the first is either 'tag' or 'text';
|
||||
* the second is the actual value.
|
||||
*
|
||||
* Based on the _tokenize() subroutine from Brad Choate's MTRegex plugin.
|
||||
* <http://www.bradchoate.com/past/mtregex.php>
|
||||
*/
|
||||
const _tokenize = (str) => {
|
||||
var pos = 0;
|
||||
var len = str.length;
|
||||
var tokens = [];
|
||||
var match = /<!--[\s\S]*?-->|<\?.*?\?>|<[^>]*>/g;
|
||||
var matched = null;
|
||||
while (matched = match.exec(str)) { // eslint-disable-line no-cond-assign
|
||||
if (pos < matched.index) {
|
||||
let t = ['text', str.substring(pos, matched.index)];
|
||||
tokens.push(t);
|
||||
}
|
||||
let t = ['tag', matched.toString()];
|
||||
tokens.push(t);
|
||||
pos = match.lastIndex;
|
||||
}
|
||||
if (pos < len) {
|
||||
let t = ['text', str.substring(pos, len)];
|
||||
tokens.push(t);
|
||||
}
|
||||
return tokens;
|
||||
};
|
||||
|
||||
function markedSmartypants({
|
||||
config = 2,
|
||||
} = {}) {
|
||||
return {
|
||||
tokenizer: {
|
||||
inlineText(src) {
|
||||
// don't escape inlineText
|
||||
const cap = this.rules.inline.text.exec(src);
|
||||
|
||||
/* istanbul ignore next */
|
||||
if (!cap) {
|
||||
// should never happen
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'text',
|
||||
raw: cap[0],
|
||||
text: cap[0],
|
||||
};
|
||||
},
|
||||
},
|
||||
hooks: {
|
||||
postprocess(html) {
|
||||
return SmartyPants(html, config);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
exports.markedSmartypants = markedSmartypants;
|
||||
471
node_modules/marked-smartypants/lib/index.mjs
generated
vendored
Normal file
471
node_modules/marked-smartypants/lib/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,471 @@
|
||||
const tags_to_skip = /<(\/?)(?:pre|code|kbd|script|math)[^>]*>/i;
|
||||
/**
|
||||
* @param text text to be parsed
|
||||
* @param attr value of the smart_quotes="" attribute
|
||||
*/
|
||||
const SmartyPants = (text = '', attr = '1') => {
|
||||
var do_quotes;
|
||||
var do_backticks;
|
||||
var do_dashes;
|
||||
var do_ellipses;
|
||||
var do_stupefy;
|
||||
var convert_quot = 0;
|
||||
if (typeof attr === 'number') {
|
||||
attr = attr.toString();
|
||||
}
|
||||
else {
|
||||
attr = attr.replace(/\s/g, '');
|
||||
}
|
||||
/**
|
||||
* Parse attributes:
|
||||
* 0 : do nothing
|
||||
* 1 : set all
|
||||
* 2 : set all, using old school en- and em- dash shortcuts
|
||||
* 3 : set all, using inverted old school en and em- dash shortcuts
|
||||
*
|
||||
* q : quotes
|
||||
* b : backtick quotes (``double'' only)
|
||||
* B : backtick quotes (``double'' and `single')
|
||||
* d : dashes
|
||||
* D : old school dashes
|
||||
* i : inverted old school dashes
|
||||
* e : ellipses
|
||||
* w : convert " entities to " for Dreamweaver users
|
||||
*/
|
||||
if (attr === '0') {
|
||||
// Do nothing
|
||||
return text;
|
||||
}
|
||||
else if (attr === '1') {
|
||||
// Do everything, turn all options on.
|
||||
do_quotes = 1;
|
||||
do_backticks = 1;
|
||||
do_dashes = 1;
|
||||
do_ellipses = 1;
|
||||
}
|
||||
else if (attr === '2') {
|
||||
// Do everything, turn all options on, use old school dash shorthand.
|
||||
do_quotes = 1;
|
||||
do_backticks = 1;
|
||||
do_dashes = 2;
|
||||
do_ellipses = 1;
|
||||
}
|
||||
else if (attr === '3') {
|
||||
// Do everything, turn all options on, use inverted old school dash shorthand.
|
||||
do_quotes = 1;
|
||||
do_backticks = 1;
|
||||
do_dashes = 3;
|
||||
do_ellipses = 1;
|
||||
}
|
||||
else if (attr === '-1') {
|
||||
// Special "stupefy" mode.
|
||||
do_stupefy = 1;
|
||||
}
|
||||
else {
|
||||
for (let i = 0; i < attr.length; i++) {
|
||||
let c = attr[i];
|
||||
if (c === 'q') {
|
||||
do_quotes = 1;
|
||||
}
|
||||
if (c === 'b') {
|
||||
do_backticks = 1;
|
||||
}
|
||||
if (c === 'B') {
|
||||
do_backticks = 2;
|
||||
}
|
||||
if (c === 'd') {
|
||||
do_dashes = 1;
|
||||
}
|
||||
if (c === 'D') {
|
||||
do_dashes = 2;
|
||||
}
|
||||
if (c === 'i') {
|
||||
do_dashes = 3;
|
||||
}
|
||||
if (c === 'e') {
|
||||
do_ellipses = 1;
|
||||
}
|
||||
if (c === 'w') {
|
||||
convert_quot = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
var tokens = _tokenize(text);
|
||||
var result = '';
|
||||
/**
|
||||
* Keep track of when we're inside <pre> or <code> tags.
|
||||
*/
|
||||
var in_pre = 0;
|
||||
/**
|
||||
* This is a cheat, used to get some context
|
||||
* for one-character tokens that consist of
|
||||
* just a quote char. What we do is remember
|
||||
* the last character of the previous text
|
||||
* token, to use as context to curl single-
|
||||
* character quote tokens correctly.
|
||||
*/
|
||||
var prev_token_last_char = '';
|
||||
for (let i = 0; i < tokens.length; i++) {
|
||||
let cur_token = tokens[i];
|
||||
if (cur_token[0] === 'tag') {
|
||||
result = result + cur_token[1];
|
||||
let matched = tags_to_skip.exec(cur_token[1]);
|
||||
if (matched) {
|
||||
if (matched[1] === '/') {
|
||||
in_pre = 0;
|
||||
}
|
||||
else {
|
||||
in_pre = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
let t = cur_token[1];
|
||||
let last_char = t.substring(t.length - 1, t.length); // Remember last char of this token before processing.
|
||||
if (!in_pre) {
|
||||
t = ProcessEscapes(t);
|
||||
if (convert_quot) {
|
||||
t = t.replace(/$quot;/g, '"');
|
||||
}
|
||||
if (do_dashes) {
|
||||
if (do_dashes === 1) {
|
||||
t = EducateDashes(t);
|
||||
}
|
||||
if (do_dashes === 2) {
|
||||
t = EducateDashesOldSchool(t);
|
||||
}
|
||||
if (do_dashes === 3) {
|
||||
t = EducateDashesOldSchoolInverted(t);
|
||||
}
|
||||
}
|
||||
if (do_ellipses) {
|
||||
t = EducateEllipses(t);
|
||||
}
|
||||
// Note: backticks need to be processed before quotes.
|
||||
if (do_backticks) {
|
||||
t = EducateBackticks(t);
|
||||
if (do_backticks === 2) {
|
||||
t = EducateSingleBackticks(t);
|
||||
}
|
||||
}
|
||||
if (do_quotes) {
|
||||
if (t === '\'') {
|
||||
// Special case: single-character ' token
|
||||
if (/\S/.test(prev_token_last_char)) {
|
||||
t = '’';
|
||||
}
|
||||
else {
|
||||
t = '‘';
|
||||
}
|
||||
}
|
||||
else if (t === '"') {
|
||||
// Special case: single-character " token
|
||||
if (/\S/.test(prev_token_last_char)) {
|
||||
t = '”';
|
||||
}
|
||||
else {
|
||||
t = '“';
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Normal case:
|
||||
t = EducateQuotes(t);
|
||||
}
|
||||
}
|
||||
if (do_stupefy) {
|
||||
t = StupefyEntities(t);
|
||||
}
|
||||
}
|
||||
prev_token_last_char = last_char;
|
||||
result = result + t;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with "educated" curly quote HTML entities.
|
||||
*
|
||||
* Example input: "Isn't this fun?"
|
||||
* Example output: “Isn’t this fun?”
|
||||
*/
|
||||
const EducateQuotes = (str) => {
|
||||
/**
|
||||
* Make our own "punctuation" character class, because the POSIX-style
|
||||
* [:PUNCT:] is only available in Perl 5.6 or later:
|
||||
*
|
||||
* JavaScript don't have punctuation class neither.
|
||||
*/
|
||||
var punct_class = '[!"#\$\%\'()*+,-./:;<=>?\@\[\\\]\^_`{|}~]'; // eslint-disable-line no-useless-escape
|
||||
/**
|
||||
* Special case if the very first character is a quote
|
||||
* followed by punctuation at a non-word-break. Close the quotes by brute force:
|
||||
*/
|
||||
str = str.replace(new RegExp(`^'(?=${punct_class}\\B)`), '’'); // eslint-disable-line no-useless-escape
|
||||
str = str.replace(new RegExp(`^"(?=${punct_class}\\B)`), '”'); // eslint-disable-line no-useless-escape
|
||||
/**
|
||||
* Special case for double sets of quotes, e.g.:
|
||||
* <p>He said, "'Quoted' words in a larger quote."</p>
|
||||
*/
|
||||
str = str.replace(/"'(?=\w)/, '“‘');
|
||||
str = str.replace(/'"(?=\w)/, '‘“');
|
||||
/**
|
||||
* Special case for decade abbreviations (the '80s):
|
||||
*/
|
||||
str = str.replace(/'(?=\d\d)/, '’');
|
||||
var close_class = '[^\\ \\t\\r\\n\\[\\{\\(\\-]'; // eslint-disable-line no-useless-escape
|
||||
var not_close_class = '[\\ \\t\\r\\n\\[\\{\\(\\-]'; // eslint-disable-line no-useless-escape
|
||||
var dec_dashes = '–|—';
|
||||
/**
|
||||
* Get most opening single quotes:
|
||||
* s {
|
||||
* (
|
||||
* \s | # a whitespace char, or
|
||||
* | # a non-breaking space entity, or
|
||||
* -- | # dashes, or
|
||||
* &[mn]dash; | # named dash entities
|
||||
* $dec_dashes | # or decimal entities
|
||||
* &\#x201[34]; # or hex
|
||||
* )
|
||||
* ' # the quote
|
||||
* (?=\w) # followed by a word character
|
||||
* } {$1‘}xg;
|
||||
*/
|
||||
str = str.replace(new RegExp(`(\\s| |--|&[mn]dash;|${dec_dashes}|ȁ[34])'(?=\\w)`, 'g'), '\$1‘'); // eslint-disable-line no-useless-escape
|
||||
/**
|
||||
* Single closing quotes:
|
||||
* s {
|
||||
* ($close_class)?
|
||||
* '
|
||||
* (?(1)| # If $1 captured, then do nothing;
|
||||
* (?=\s | s\b) # otherwise, positive lookahead for a whitespace
|
||||
* ) # char or an 's' at a word ending position. This
|
||||
* # is a special case to handle something like:
|
||||
* # "<i>Custer</i>'s Last Stand."
|
||||
* } {$1’}xgi;
|
||||
*/
|
||||
str = str.replace(new RegExp(`(${close_class})'`, 'g'), '\$1’'); // eslint-disable-line no-useless-escape
|
||||
str = str.replace(new RegExp(`(${not_close_class}?)'(?=\\s|s\\b)`, 'g'), '\$1’'); // eslint-disable-line no-useless-escape
|
||||
/**
|
||||
* Any remaining single quotes should be opening ones:
|
||||
*/
|
||||
str = str.replace(/'/g, '‘');
|
||||
/**
|
||||
* Get most opening double quotes:
|
||||
* s {
|
||||
* (
|
||||
* \s | # a whitespace char, or
|
||||
* | # a non-breaking space entity, or
|
||||
* -- | # dashes, or
|
||||
* &[mn]dash; | # named dash entities
|
||||
* $dec_dashes | # or decimal entities
|
||||
* &\#x201[34]; # or hex
|
||||
* )
|
||||
* " # the quote
|
||||
* (?=\w) # followed by a word character
|
||||
* } {$1“}xg;
|
||||
*/
|
||||
str = str.replace(new RegExp(`(\\s| |--|&[mn]dash;|${dec_dashes}|ȁ[34])"(?=\\w)`, 'g'), '\$1“'); // eslint-disable-line no-useless-escape
|
||||
/**
|
||||
* Double closing quotes:
|
||||
* s {
|
||||
* ($close_class)?
|
||||
* "
|
||||
* (?(1)|(?=\s)) # If $1 captured, then do nothing;
|
||||
* # if not, then make sure the next char is whitespace.
|
||||
* } {$1”}xg;
|
||||
*/
|
||||
str = str.replace(new RegExp(`(${close_class})"`, 'g'), '\$1”'); // eslint-disable-line no-useless-escape
|
||||
str = str.replace(new RegExp(`(${not_close_class}?)"(?=\\s)`, 'g'), '\$1”'); // eslint-disable-line no-useless-escape
|
||||
/**
|
||||
* Any remaining quotes should be opening ones.
|
||||
*/
|
||||
str = str.replace(/"/g, '“');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with ``backticks'' -style double quotes
|
||||
* translated into HTML curly quote entities.
|
||||
*
|
||||
* Example input: ``Isn't this fun?''
|
||||
* Example output: “Isn't this fun?”
|
||||
*/
|
||||
const EducateBackticks = (str) => {
|
||||
str = str.replace(/``/g, '“');
|
||||
str = str.replace(/''/g, '”');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with `backticks' -style single quotes
|
||||
* translated into HTML curly quote entities.
|
||||
*
|
||||
* Example input: `Isn't this fun?'
|
||||
* Example output: ‘Isn’t this fun?’
|
||||
*/
|
||||
const EducateSingleBackticks = (str) => {
|
||||
str = str.replace(/`/g, '‘');
|
||||
str = str.replace(/'/g, '’');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with each instance of "--" translated to
|
||||
* an em-dash HTML entity.
|
||||
*/
|
||||
const EducateDashes = (str) => {
|
||||
str = str.replace(/--/g, '—');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with each instance of "--" translated to
|
||||
* an en-dash HTML entity, and each "---" translated to
|
||||
* an em-dash HTML entity.
|
||||
*/
|
||||
const EducateDashesOldSchool = (str) => {
|
||||
str = str.replace(/---/g, '—');
|
||||
str = str.replace(/--/g, '–');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with each instance of "--" translated to
|
||||
* an em-dash HTML entity, and each "---" translated to
|
||||
* an en-dash HTML entity. Two reasons why: First, unlike the
|
||||
* en- and em-dash syntax supported by
|
||||
* EducateDashesOldSchool(), it's compatible with existing
|
||||
* entries written before SmartyPants 1.1, back when "--" was
|
||||
* only used for em-dashes. Second, em-dashes are more
|
||||
* common than en-dashes, and so it sort of makes sense that
|
||||
* the shortcut should be shorter to type. (Thanks to Aaron
|
||||
* Swartz for the idea.)
|
||||
*/
|
||||
const EducateDashesOldSchoolInverted = (str) => {
|
||||
str = str.replace(/---/g, '–');
|
||||
str = str.replace(/--/g, '—');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with each instance of "..." translated to
|
||||
* an ellipsis HTML entity. Also converts the case where
|
||||
* there are spaces between the dots.
|
||||
*
|
||||
* Example input: Huh...?
|
||||
* Example output: Huh…?
|
||||
*/
|
||||
const EducateEllipses = (str) => {
|
||||
str = str.replace(/\.\.\./g, '…');
|
||||
str = str.replace(/\. \. \./g, '…');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with each SmartyPants HTML entity translated to
|
||||
* its ASCII counterpart.
|
||||
*
|
||||
* Example input: “Hello — world.”
|
||||
* Example output: "Hello -- world."
|
||||
*/
|
||||
const StupefyEntities = (str) => {
|
||||
str = str.replace(/–/g, '-'); // en-dash
|
||||
str = str.replace(/—/g, '--'); // em-dash
|
||||
str = str.replace(/‘/g, '\''); // open single quote
|
||||
str = str.replace(/’/g, '\''); // close single quote
|
||||
str = str.replace(/“/g, '"'); // open double quote
|
||||
str = str.replace(/”/g, '"'); // close double quote
|
||||
str = str.replace(/…/g, '...'); // ellipsis
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} string, with after processing the following backslash
|
||||
* escape sequences. This is useful if you want to force a "dumb"
|
||||
* quote or other character to appear.
|
||||
*
|
||||
* Escape Value
|
||||
* ------ -----
|
||||
* \\ \
|
||||
* \" "
|
||||
* \' '
|
||||
* \. .
|
||||
* \- -
|
||||
* \` `
|
||||
*
|
||||
*/
|
||||
const ProcessEscapes = (str) => {
|
||||
str = str.replace(/\\\\/g, '\');
|
||||
str = str.replace(/\\"/g, '"');
|
||||
str = str.replace(/\\'/g, ''');
|
||||
str = str.replace(/\\\./g, '.');
|
||||
str = str.replace(/\\-/g, '-');
|
||||
str = str.replace(/\\`/g, '`');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String containing HTML markup.
|
||||
* @return {Array<token>} Reference to an array of the tokens comprising the input
|
||||
* string. Each token is either a tag (possibly with nested,
|
||||
* tags contained therein, such as <a href="<MTFoo>">, or a
|
||||
* run of text between tags. Each element of the array is a
|
||||
* two-element array; the first is either 'tag' or 'text';
|
||||
* the second is the actual value.
|
||||
*
|
||||
* Based on the _tokenize() subroutine from Brad Choate's MTRegex plugin.
|
||||
* <http://www.bradchoate.com/past/mtregex.php>
|
||||
*/
|
||||
const _tokenize = (str) => {
|
||||
var pos = 0;
|
||||
var len = str.length;
|
||||
var tokens = [];
|
||||
var match = /<!--[\s\S]*?-->|<\?.*?\?>|<[^>]*>/g;
|
||||
var matched = null;
|
||||
while (matched = match.exec(str)) { // eslint-disable-line no-cond-assign
|
||||
if (pos < matched.index) {
|
||||
let t = ['text', str.substring(pos, matched.index)];
|
||||
tokens.push(t);
|
||||
}
|
||||
let t = ['tag', matched.toString()];
|
||||
tokens.push(t);
|
||||
pos = match.lastIndex;
|
||||
}
|
||||
if (pos < len) {
|
||||
let t = ['text', str.substring(pos, len)];
|
||||
tokens.push(t);
|
||||
}
|
||||
return tokens;
|
||||
};
|
||||
|
||||
function markedSmartypants({
|
||||
config = 2,
|
||||
} = {}) {
|
||||
return {
|
||||
tokenizer: {
|
||||
inlineText(src) {
|
||||
// don't escape inlineText
|
||||
const cap = this.rules.inline.text.exec(src);
|
||||
|
||||
/* istanbul ignore next */
|
||||
if (!cap) {
|
||||
// should never happen
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'text',
|
||||
raw: cap[0],
|
||||
text: cap[0],
|
||||
};
|
||||
},
|
||||
},
|
||||
hooks: {
|
||||
postprocess(html) {
|
||||
return SmartyPants(html, config);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export { markedSmartypants };
|
||||
479
node_modules/marked-smartypants/lib/index.umd.js
generated
vendored
Normal file
479
node_modules/marked-smartypants/lib/index.umd.js
generated
vendored
Normal file
@@ -0,0 +1,479 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
||||
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.markedSmartypants = {}));
|
||||
})(this, (function (exports) { 'use strict';
|
||||
|
||||
const tags_to_skip = /<(\/?)(?:pre|code|kbd|script|math)[^>]*>/i;
|
||||
/**
|
||||
* @param text text to be parsed
|
||||
* @param attr value of the smart_quotes="" attribute
|
||||
*/
|
||||
const SmartyPants = (text = '', attr = '1') => {
|
||||
var do_quotes;
|
||||
var do_backticks;
|
||||
var do_dashes;
|
||||
var do_ellipses;
|
||||
var do_stupefy;
|
||||
var convert_quot = 0;
|
||||
if (typeof attr === 'number') {
|
||||
attr = attr.toString();
|
||||
}
|
||||
else {
|
||||
attr = attr.replace(/\s/g, '');
|
||||
}
|
||||
/**
|
||||
* Parse attributes:
|
||||
* 0 : do nothing
|
||||
* 1 : set all
|
||||
* 2 : set all, using old school en- and em- dash shortcuts
|
||||
* 3 : set all, using inverted old school en and em- dash shortcuts
|
||||
*
|
||||
* q : quotes
|
||||
* b : backtick quotes (``double'' only)
|
||||
* B : backtick quotes (``double'' and `single')
|
||||
* d : dashes
|
||||
* D : old school dashes
|
||||
* i : inverted old school dashes
|
||||
* e : ellipses
|
||||
* w : convert " entities to " for Dreamweaver users
|
||||
*/
|
||||
if (attr === '0') {
|
||||
// Do nothing
|
||||
return text;
|
||||
}
|
||||
else if (attr === '1') {
|
||||
// Do everything, turn all options on.
|
||||
do_quotes = 1;
|
||||
do_backticks = 1;
|
||||
do_dashes = 1;
|
||||
do_ellipses = 1;
|
||||
}
|
||||
else if (attr === '2') {
|
||||
// Do everything, turn all options on, use old school dash shorthand.
|
||||
do_quotes = 1;
|
||||
do_backticks = 1;
|
||||
do_dashes = 2;
|
||||
do_ellipses = 1;
|
||||
}
|
||||
else if (attr === '3') {
|
||||
// Do everything, turn all options on, use inverted old school dash shorthand.
|
||||
do_quotes = 1;
|
||||
do_backticks = 1;
|
||||
do_dashes = 3;
|
||||
do_ellipses = 1;
|
||||
}
|
||||
else if (attr === '-1') {
|
||||
// Special "stupefy" mode.
|
||||
do_stupefy = 1;
|
||||
}
|
||||
else {
|
||||
for (let i = 0; i < attr.length; i++) {
|
||||
let c = attr[i];
|
||||
if (c === 'q') {
|
||||
do_quotes = 1;
|
||||
}
|
||||
if (c === 'b') {
|
||||
do_backticks = 1;
|
||||
}
|
||||
if (c === 'B') {
|
||||
do_backticks = 2;
|
||||
}
|
||||
if (c === 'd') {
|
||||
do_dashes = 1;
|
||||
}
|
||||
if (c === 'D') {
|
||||
do_dashes = 2;
|
||||
}
|
||||
if (c === 'i') {
|
||||
do_dashes = 3;
|
||||
}
|
||||
if (c === 'e') {
|
||||
do_ellipses = 1;
|
||||
}
|
||||
if (c === 'w') {
|
||||
convert_quot = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
var tokens = _tokenize(text);
|
||||
var result = '';
|
||||
/**
|
||||
* Keep track of when we're inside <pre> or <code> tags.
|
||||
*/
|
||||
var in_pre = 0;
|
||||
/**
|
||||
* This is a cheat, used to get some context
|
||||
* for one-character tokens that consist of
|
||||
* just a quote char. What we do is remember
|
||||
* the last character of the previous text
|
||||
* token, to use as context to curl single-
|
||||
* character quote tokens correctly.
|
||||
*/
|
||||
var prev_token_last_char = '';
|
||||
for (let i = 0; i < tokens.length; i++) {
|
||||
let cur_token = tokens[i];
|
||||
if (cur_token[0] === 'tag') {
|
||||
result = result + cur_token[1];
|
||||
let matched = tags_to_skip.exec(cur_token[1]);
|
||||
if (matched) {
|
||||
if (matched[1] === '/') {
|
||||
in_pre = 0;
|
||||
}
|
||||
else {
|
||||
in_pre = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
let t = cur_token[1];
|
||||
let last_char = t.substring(t.length - 1, t.length); // Remember last char of this token before processing.
|
||||
if (!in_pre) {
|
||||
t = ProcessEscapes(t);
|
||||
if (convert_quot) {
|
||||
t = t.replace(/$quot;/g, '"');
|
||||
}
|
||||
if (do_dashes) {
|
||||
if (do_dashes === 1) {
|
||||
t = EducateDashes(t);
|
||||
}
|
||||
if (do_dashes === 2) {
|
||||
t = EducateDashesOldSchool(t);
|
||||
}
|
||||
if (do_dashes === 3) {
|
||||
t = EducateDashesOldSchoolInverted(t);
|
||||
}
|
||||
}
|
||||
if (do_ellipses) {
|
||||
t = EducateEllipses(t);
|
||||
}
|
||||
// Note: backticks need to be processed before quotes.
|
||||
if (do_backticks) {
|
||||
t = EducateBackticks(t);
|
||||
if (do_backticks === 2) {
|
||||
t = EducateSingleBackticks(t);
|
||||
}
|
||||
}
|
||||
if (do_quotes) {
|
||||
if (t === '\'') {
|
||||
// Special case: single-character ' token
|
||||
if (/\S/.test(prev_token_last_char)) {
|
||||
t = '’';
|
||||
}
|
||||
else {
|
||||
t = '‘';
|
||||
}
|
||||
}
|
||||
else if (t === '"') {
|
||||
// Special case: single-character " token
|
||||
if (/\S/.test(prev_token_last_char)) {
|
||||
t = '”';
|
||||
}
|
||||
else {
|
||||
t = '“';
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Normal case:
|
||||
t = EducateQuotes(t);
|
||||
}
|
||||
}
|
||||
if (do_stupefy) {
|
||||
t = StupefyEntities(t);
|
||||
}
|
||||
}
|
||||
prev_token_last_char = last_char;
|
||||
result = result + t;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with "educated" curly quote HTML entities.
|
||||
*
|
||||
* Example input: "Isn't this fun?"
|
||||
* Example output: “Isn’t this fun?”
|
||||
*/
|
||||
const EducateQuotes = (str) => {
|
||||
/**
|
||||
* Make our own "punctuation" character class, because the POSIX-style
|
||||
* [:PUNCT:] is only available in Perl 5.6 or later:
|
||||
*
|
||||
* JavaScript don't have punctuation class neither.
|
||||
*/
|
||||
var punct_class = '[!"#\$\%\'()*+,-./:;<=>?\@\[\\\]\^_`{|}~]'; // eslint-disable-line no-useless-escape
|
||||
/**
|
||||
* Special case if the very first character is a quote
|
||||
* followed by punctuation at a non-word-break. Close the quotes by brute force:
|
||||
*/
|
||||
str = str.replace(new RegExp(`^'(?=${punct_class}\\B)`), '’'); // eslint-disable-line no-useless-escape
|
||||
str = str.replace(new RegExp(`^"(?=${punct_class}\\B)`), '”'); // eslint-disable-line no-useless-escape
|
||||
/**
|
||||
* Special case for double sets of quotes, e.g.:
|
||||
* <p>He said, "'Quoted' words in a larger quote."</p>
|
||||
*/
|
||||
str = str.replace(/"'(?=\w)/, '“‘');
|
||||
str = str.replace(/'"(?=\w)/, '‘“');
|
||||
/**
|
||||
* Special case for decade abbreviations (the '80s):
|
||||
*/
|
||||
str = str.replace(/'(?=\d\d)/, '’');
|
||||
var close_class = '[^\\ \\t\\r\\n\\[\\{\\(\\-]'; // eslint-disable-line no-useless-escape
|
||||
var not_close_class = '[\\ \\t\\r\\n\\[\\{\\(\\-]'; // eslint-disable-line no-useless-escape
|
||||
var dec_dashes = '–|—';
|
||||
/**
|
||||
* Get most opening single quotes:
|
||||
* s {
|
||||
* (
|
||||
* \s | # a whitespace char, or
|
||||
* | # a non-breaking space entity, or
|
||||
* -- | # dashes, or
|
||||
* &[mn]dash; | # named dash entities
|
||||
* $dec_dashes | # or decimal entities
|
||||
* &\#x201[34]; # or hex
|
||||
* )
|
||||
* ' # the quote
|
||||
* (?=\w) # followed by a word character
|
||||
* } {$1‘}xg;
|
||||
*/
|
||||
str = str.replace(new RegExp(`(\\s| |--|&[mn]dash;|${dec_dashes}|ȁ[34])'(?=\\w)`, 'g'), '\$1‘'); // eslint-disable-line no-useless-escape
|
||||
/**
|
||||
* Single closing quotes:
|
||||
* s {
|
||||
* ($close_class)?
|
||||
* '
|
||||
* (?(1)| # If $1 captured, then do nothing;
|
||||
* (?=\s | s\b) # otherwise, positive lookahead for a whitespace
|
||||
* ) # char or an 's' at a word ending position. This
|
||||
* # is a special case to handle something like:
|
||||
* # "<i>Custer</i>'s Last Stand."
|
||||
* } {$1’}xgi;
|
||||
*/
|
||||
str = str.replace(new RegExp(`(${close_class})'`, 'g'), '\$1’'); // eslint-disable-line no-useless-escape
|
||||
str = str.replace(new RegExp(`(${not_close_class}?)'(?=\\s|s\\b)`, 'g'), '\$1’'); // eslint-disable-line no-useless-escape
|
||||
/**
|
||||
* Any remaining single quotes should be opening ones:
|
||||
*/
|
||||
str = str.replace(/'/g, '‘');
|
||||
/**
|
||||
* Get most opening double quotes:
|
||||
* s {
|
||||
* (
|
||||
* \s | # a whitespace char, or
|
||||
* | # a non-breaking space entity, or
|
||||
* -- | # dashes, or
|
||||
* &[mn]dash; | # named dash entities
|
||||
* $dec_dashes | # or decimal entities
|
||||
* &\#x201[34]; # or hex
|
||||
* )
|
||||
* " # the quote
|
||||
* (?=\w) # followed by a word character
|
||||
* } {$1“}xg;
|
||||
*/
|
||||
str = str.replace(new RegExp(`(\\s| |--|&[mn]dash;|${dec_dashes}|ȁ[34])"(?=\\w)`, 'g'), '\$1“'); // eslint-disable-line no-useless-escape
|
||||
/**
|
||||
* Double closing quotes:
|
||||
* s {
|
||||
* ($close_class)?
|
||||
* "
|
||||
* (?(1)|(?=\s)) # If $1 captured, then do nothing;
|
||||
* # if not, then make sure the next char is whitespace.
|
||||
* } {$1”}xg;
|
||||
*/
|
||||
str = str.replace(new RegExp(`(${close_class})"`, 'g'), '\$1”'); // eslint-disable-line no-useless-escape
|
||||
str = str.replace(new RegExp(`(${not_close_class}?)"(?=\\s)`, 'g'), '\$1”'); // eslint-disable-line no-useless-escape
|
||||
/**
|
||||
* Any remaining quotes should be opening ones.
|
||||
*/
|
||||
str = str.replace(/"/g, '“');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with ``backticks'' -style double quotes
|
||||
* translated into HTML curly quote entities.
|
||||
*
|
||||
* Example input: ``Isn't this fun?''
|
||||
* Example output: “Isn't this fun?”
|
||||
*/
|
||||
const EducateBackticks = (str) => {
|
||||
str = str.replace(/``/g, '“');
|
||||
str = str.replace(/''/g, '”');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with `backticks' -style single quotes
|
||||
* translated into HTML curly quote entities.
|
||||
*
|
||||
* Example input: `Isn't this fun?'
|
||||
* Example output: ‘Isn’t this fun?’
|
||||
*/
|
||||
const EducateSingleBackticks = (str) => {
|
||||
str = str.replace(/`/g, '‘');
|
||||
str = str.replace(/'/g, '’');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with each instance of "--" translated to
|
||||
* an em-dash HTML entity.
|
||||
*/
|
||||
const EducateDashes = (str) => {
|
||||
str = str.replace(/--/g, '—');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with each instance of "--" translated to
|
||||
* an en-dash HTML entity, and each "---" translated to
|
||||
* an em-dash HTML entity.
|
||||
*/
|
||||
const EducateDashesOldSchool = (str) => {
|
||||
str = str.replace(/---/g, '—');
|
||||
str = str.replace(/--/g, '–');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with each instance of "--" translated to
|
||||
* an em-dash HTML entity, and each "---" translated to
|
||||
* an en-dash HTML entity. Two reasons why: First, unlike the
|
||||
* en- and em-dash syntax supported by
|
||||
* EducateDashesOldSchool(), it's compatible with existing
|
||||
* entries written before SmartyPants 1.1, back when "--" was
|
||||
* only used for em-dashes. Second, em-dashes are more
|
||||
* common than en-dashes, and so it sort of makes sense that
|
||||
* the shortcut should be shorter to type. (Thanks to Aaron
|
||||
* Swartz for the idea.)
|
||||
*/
|
||||
const EducateDashesOldSchoolInverted = (str) => {
|
||||
str = str.replace(/---/g, '–');
|
||||
str = str.replace(/--/g, '—');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with each instance of "..." translated to
|
||||
* an ellipsis HTML entity. Also converts the case where
|
||||
* there are spaces between the dots.
|
||||
*
|
||||
* Example input: Huh...?
|
||||
* Example output: Huh…?
|
||||
*/
|
||||
const EducateEllipses = (str) => {
|
||||
str = str.replace(/\.\.\./g, '…');
|
||||
str = str.replace(/\. \. \./g, '…');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} The string, with each SmartyPants HTML entity translated to
|
||||
* its ASCII counterpart.
|
||||
*
|
||||
* Example input: “Hello — world.”
|
||||
* Example output: "Hello -- world."
|
||||
*/
|
||||
const StupefyEntities = (str) => {
|
||||
str = str.replace(/–/g, '-'); // en-dash
|
||||
str = str.replace(/—/g, '--'); // em-dash
|
||||
str = str.replace(/‘/g, '\''); // open single quote
|
||||
str = str.replace(/’/g, '\''); // close single quote
|
||||
str = str.replace(/“/g, '"'); // open double quote
|
||||
str = str.replace(/”/g, '"'); // close double quote
|
||||
str = str.replace(/…/g, '...'); // ellipsis
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String
|
||||
* @return {string} string, with after processing the following backslash
|
||||
* escape sequences. This is useful if you want to force a "dumb"
|
||||
* quote or other character to appear.
|
||||
*
|
||||
* Escape Value
|
||||
* ------ -----
|
||||
* \\ \
|
||||
* \" "
|
||||
* \' '
|
||||
* \. .
|
||||
* \- -
|
||||
* \` `
|
||||
*
|
||||
*/
|
||||
const ProcessEscapes = (str) => {
|
||||
str = str.replace(/\\\\/g, '\');
|
||||
str = str.replace(/\\"/g, '"');
|
||||
str = str.replace(/\\'/g, ''');
|
||||
str = str.replace(/\\\./g, '.');
|
||||
str = str.replace(/\\-/g, '-');
|
||||
str = str.replace(/\\`/g, '`');
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* @param {string} str String containing HTML markup.
|
||||
* @return {Array<token>} Reference to an array of the tokens comprising the input
|
||||
* string. Each token is either a tag (possibly with nested,
|
||||
* tags contained therein, such as <a href="<MTFoo>">, or a
|
||||
* run of text between tags. Each element of the array is a
|
||||
* two-element array; the first is either 'tag' or 'text';
|
||||
* the second is the actual value.
|
||||
*
|
||||
* Based on the _tokenize() subroutine from Brad Choate's MTRegex plugin.
|
||||
* <http://www.bradchoate.com/past/mtregex.php>
|
||||
*/
|
||||
const _tokenize = (str) => {
|
||||
var pos = 0;
|
||||
var len = str.length;
|
||||
var tokens = [];
|
||||
var match = /<!--[\s\S]*?-->|<\?.*?\?>|<[^>]*>/g;
|
||||
var matched = null;
|
||||
while (matched = match.exec(str)) { // eslint-disable-line no-cond-assign
|
||||
if (pos < matched.index) {
|
||||
let t = ['text', str.substring(pos, matched.index)];
|
||||
tokens.push(t);
|
||||
}
|
||||
let t = ['tag', matched.toString()];
|
||||
tokens.push(t);
|
||||
pos = match.lastIndex;
|
||||
}
|
||||
if (pos < len) {
|
||||
let t = ['text', str.substring(pos, len)];
|
||||
tokens.push(t);
|
||||
}
|
||||
return tokens;
|
||||
};
|
||||
|
||||
function markedSmartypants({
|
||||
config = 2,
|
||||
} = {}) {
|
||||
return {
|
||||
tokenizer: {
|
||||
inlineText(src) {
|
||||
// don't escape inlineText
|
||||
const cap = this.rules.inline.text.exec(src);
|
||||
|
||||
/* istanbul ignore next */
|
||||
if (!cap) {
|
||||
// should never happen
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'text',
|
||||
raw: cap[0],
|
||||
text: cap[0],
|
||||
};
|
||||
},
|
||||
},
|
||||
hooks: {
|
||||
postprocess(html) {
|
||||
return SmartyPants(html, config);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
exports.markedSmartypants = markedSmartypants;
|
||||
|
||||
}));
|
||||
65
node_modules/marked-smartypants/package.json
generated
vendored
Normal file
65
node_modules/marked-smartypants/package.json
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"name": "marked-smartypants",
|
||||
"version": "1.1.8",
|
||||
"description": "marked extension for smartypants",
|
||||
"main": "./lib/index.cjs",
|
||||
"module": "./lib/index.mjs",
|
||||
"browser": "./lib/index.umd.js",
|
||||
"type": "module",
|
||||
"types": "./src/index.d.ts",
|
||||
"keywords": [
|
||||
"marked",
|
||||
"extension",
|
||||
"smartypants"
|
||||
],
|
||||
"files": [
|
||||
"lib/",
|
||||
"src/"
|
||||
],
|
||||
"exports": {
|
||||
"types": "./src/index.d.ts",
|
||||
"import": "./lib/index.mjs",
|
||||
"require": "./lib/index.cjs"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "npm run build && cross-env NODE_OPTIONS=--experimental-vm-modules jest --verbose",
|
||||
"test:cover": "npm run build && cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage",
|
||||
"test:types": "tsd -f spec/index.test-d.ts -t src/index.d.ts",
|
||||
"lint": "eslint",
|
||||
"build": "rollup -c rollup.config.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/markedjs/marked-smartypants.git"
|
||||
},
|
||||
"author": "Tony Brix <Tony@Brix.ninja> (https://Tony.Brix.ninja)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/markedjs/marked-smartypants/issues"
|
||||
},
|
||||
"homepage": "https://github.com/markedjs/marked-smartypants#readme",
|
||||
"peerDependencies": {
|
||||
"marked": ">=4 <15"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@markedjs/eslint-config": "^1.0.1",
|
||||
"@rollup/plugin-node-resolve": "^15.2.3",
|
||||
"@semantic-release/changelog": "^6.0.3",
|
||||
"@semantic-release/commit-analyzer": "^13.0.0",
|
||||
"@semantic-release/git": "^10.0.1",
|
||||
"@semantic-release/github": "^10.1.3",
|
||||
"@semantic-release/npm": "^12.0.1",
|
||||
"@semantic-release/release-notes-generator": "^14.0.1",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "^9.8.0",
|
||||
"globals": "^15.9.0",
|
||||
"jest-cli": "^29.7.0",
|
||||
"marked": "^14.0.0",
|
||||
"rollup": "^4.20.0",
|
||||
"semantic-release": "^24.0.0",
|
||||
"tsd": "^0.31.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"smartypants": "^0.2.2"
|
||||
}
|
||||
}
|
||||
16
node_modules/marked-smartypants/src/index.d.ts
generated
vendored
Normal file
16
node_modules/marked-smartypants/src/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
|
||||
import type { marked } from 'marked';
|
||||
import type { MarkedExtension } from 'marked';
|
||||
|
||||
/**
|
||||
* Use [smartypants](https://github.com/othree/smartypants.js) for "smart" typographic punctuation for things like quotes and dashes
|
||||
*
|
||||
* @returns A {@link MarkedExtension | MarkedExtension} to be passed to {@link marked.use | `marked.use()`}
|
||||
*/
|
||||
export function markedSmartypants(options?: {
|
||||
/**
|
||||
* A number between -1 and 3 for a preset, or a string with letters for typographic rules. See [all options](https://github.com/othree/smartypants.js#options-and-configuration)
|
||||
* @default 2
|
||||
*/
|
||||
config?: string | number;
|
||||
}): MarkedExtension;
|
||||
31
node_modules/marked-smartypants/src/index.js
generated
vendored
Normal file
31
node_modules/marked-smartypants/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import { smartypants } from 'smartypants';
|
||||
|
||||
export function markedSmartypants({
|
||||
config = 2,
|
||||
} = {}) {
|
||||
return {
|
||||
tokenizer: {
|
||||
inlineText(src) {
|
||||
// don't escape inlineText
|
||||
const cap = this.rules.inline.text.exec(src);
|
||||
|
||||
/* istanbul ignore next */
|
||||
if (!cap) {
|
||||
// should never happen
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'text',
|
||||
raw: cap[0],
|
||||
text: cap[0],
|
||||
};
|
||||
},
|
||||
},
|
||||
hooks: {
|
||||
postprocess(html) {
|
||||
return smartypants(html, config);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user