Merge branch 'master' into tordev

This commit is contained in:
Riccardo Balbo 2024-10-29 11:21:25 +01:00 committed by GitHub
commit d9a51f9c1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 1 deletions

View File

@ -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 }) {

31
lib/remark-unicode.js Normal file
View File

@ -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, '')
}