-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into walletref
- Loading branch information
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { visit } from 'unist-util-visit' | ||
|
||
export default function remarkFilterUnicode () { | ||
return (tree) => { | ||
try { | ||
visit(tree, 'paragraph', (node) => { | ||
node.children = node.children.map(child => { | ||
if (child.type !== 'inlineMath') return child | ||
|
||
// if inline math contains currency symbols, rehypeMathjax will throw | ||
// see https://github.com/stackernews/stacker.news/issues/1525 | ||
// and https://github.com/stackernews/stacker.news/pull/1526 | ||
|
||
let { hChildren } = child.data | ||
hChildren = hChildren.map(child2 => { | ||
return { ...child2, value: filterUnicode(child2.value) } | ||
}) | ||
child.data.hChildren = hChildren | ||
|
||
return { ...child, value: filterUnicode(child.value) } | ||
}) | ||
}) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
} | ||
} | ||
|
||
function filterUnicode (text) { | ||
return text.replace(/\p{Sc}/u, '') | ||
} |