Skip to content

Commit

Permalink
Merge branch 'master' into walletref
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl authored Oct 30, 2024
2 parents e647d2e + 7a94288 commit 49e4fb9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion components/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 }) {
Expand Down
31 changes: 31 additions & 0 deletions lib/remark-unicode.js
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, '')
}

0 comments on commit 49e4fb9

Please sign in to comment.