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

Updated usage #4

Open
Yankie opened this issue May 30, 2024 · 0 comments
Open

Updated usage #4

Yankie opened this issue May 30, 2024 · 0 comments

Comments

@Yankie
Copy link

Yankie commented May 30, 2024

For those who's trying to go futher, here's updates to comply with current version replacements.mjs of markdown-it

  let markdownIt = require('markdown-it')({typographer: true});
  let markdownItReplaceIt = require('markdown-it-replace-it');
  
  markdownItReplaceIt.replacements.splice(0, markdownItReplaceIt.replacements.length);
  markdownItReplaceIt.replacements.push(
    {
        // +- → ±
        name: 'plusminus',
        re: /\+-/g,
        sub: '\u00b1',
        default: true
    },
    {
        // ... → … (also ?.... → ?.., !.... → !..)
        // ???????? → ???, !!!!! → !!!, `,,` → `,`
        name: 'punct',
        re: /(?:\.\.|\?\?\?\?|!!!!|,,).+/,
        sub: function (s) {
          var res = s
            .replace(/\.{2,}/g, '…')
            .replace(/([?!])/g, '$1..')
            .replace(/([?!]){4,}/g, '$1$1$1')
            .replace(/,{2,}/g, ',');
            return res
        },
        default: true
    },
    {
        // -- → –, --- → —
        name: 'dash',
        re: /--.+/,
        sub: function (s) {
          var res = s
            .replace(/(^|[^-])---(?=[^-]|$)/mg, '$1\u2014')
            .replace(/(^|\s)--(?=\s|$)/mg, '$1\u2013')
            .replace(/(^|[^-\s])--(?=[^-\s]|$)/mg, '$1\u2013');
          return res
        },
        default: true
    },
  );

  markdownIt.use(markdownItReplaceIt);
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

No branches or pull requests

1 participant