Replace unicode currency symbols in inline math
This commit is contained in:
parent
18565200e6
commit
b50bb2fcc1
|
@ -17,6 +17,7 @@ import ItemPopover from './item-popover'
|
|||
import classNames from 'classnames'
|
||||
import { CarouselProvider, useCarousel } from './carousel'
|
||||
import rehypeSN from '@/lib/rehype-sn'
|
||||
import remarkUnicode from '@/lib/remark-unicode'
|
||||
import Embed from './embed'
|
||||
import remarkMath from 'remark-math'
|
||||
import rehypeMathjax from 'rehype-mathjax'
|
||||
|
@ -33,7 +34,7 @@ const rehypeSNStyled = () => rehypeSN({
|
|||
}]
|
||||
})
|
||||
|
||||
const remarkPlugins = [gfm, [remarkMath, { singleDollarTextMath: false }]]
|
||||
const remarkPlugins = [gfm, remarkUnicode, [remarkMath, { singleDollarTextMath: false }]]
|
||||
const rehypePlugins = [rehypeSNStyled, rehypeMathjax]
|
||||
|
||||
export function SearchText ({ text }) {
|
||||
|
|
|
@ -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, '')
|
||||
}
|
Loading…
Reference in New Issue