Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
Flatten out _ chars when comparing to url (#13)
Browse files Browse the repository at this point in the history
* Flatten out _ chars when comparing to url

Fix #12

* Test with non-flattenable emphasis

Get to 100% coverage

* Remove unused babel-cli, update tap to faster v13

This removes the vulnerable dep on braces, since babel-cli isn't
actually used directly anywhere in this module anyway.
  • Loading branch information
isaacs authored and jmolivas committed Mar 26, 2019
1 parent f9a558e commit f34c42c
Show file tree
Hide file tree
Showing 5 changed files with 2,404 additions and 5,404 deletions.
16 changes: 13 additions & 3 deletions index.js
Expand Up @@ -33,11 +33,21 @@ const isTwitterLink = node => {
node.children[0].type === 'link' &&
(tweetRegexp.test(node.children[0].url) ||
momentRegexp.test(node.children[0].url)) &&
node.children[0].children.length === 1 &&
node.children[0].children[0].type === 'text' &&
node.children[0].children[0].value === node.children[0].url;
node.children[0].children.length >= 1 &&
flattenEms(node.children[0].children) === node.children[0].url;
}

// this only has to handle cases where there's a username like x_y_z, so that
// it will match the url in the link.
// It produces garbage results for stuff like `_happy *and* sad_`, because
// that could never exist in a URL anyway, so it is clearly not a match.
const flattenEms = children =>
children.reduce((flat, c) =>
(c.type === 'text') ? flat + c.value
: (c.type === 'emphasis' && c.children && c.children.length === 1)
? flat + `_${c.children[0].value}_`
: flat, '')

module.exports = async ({ markdownAST }, pluginOptions) => {
const debug = pluginOptions.debug ? console.log : () => {}

Expand Down

0 comments on commit f34c42c

Please sign in to comment.