Using replaceRE for handling Chinses unicode characters

Hi, I am the author of hugo-theme-texify. I am currently working on a feature that use dots under text (instead of bold text) to emphasize Chinese characters.

So, my current implementation looks like this:

<div class="content">
    {{ .Content | replaceRE "<strong>(\p{Han}+?)</strong>" "<strong class=chinese>$1</strong>" | safeHTML }}

where \p{Han} should match a single Chinese character, as indicated by this StackOverflow answer. This should add a chinese class to all strong elements that only contains Chinese characters.

However, instead of the expected behavior, I got this error:

Change detected, rebuilding site.
2021-02-26 14:31:33.566 +0800
Template changed "/Users/queensferry/Developer/hugo-theme-texify/layouts/_default/single.html": WRITE
Total in 8 ms
ERROR 2021/02/26 14:31:33 Rebuild failed:

ERROR 2021/02/26 14:31:33 Process: loading templates: "/Users/queensferry/Developer/hugo-theme-texify/layouts/_default/single.html:30:1": parse failed: template: _default/single.html:30: invalid syntax


And the regex works fine on regex101. com.

Some additional information that might be relevant:

queensferry in hugo-theme-texify on master [!] 
➜ hugo version
Hugo Static Site Generator v0.80.0 darwin/amd64 BuildDate: unknown
queensferry in hugo-theme-texify on master [!] 
➜ make dev
hugo server \
        --buildDrafts \
        --config="exampleSite/config.toml" \
        --contentDir="exampleSite/content" \
        --disableFastRender \

I can’t really figure out why this doesn’t work, so am here seeking help.

The forum search wields several results about invalid syntax.

Please look it up.

1 Like

Thanks! And sorry for the stupid question. I just need to escape the regex like this: <strong>(\\p{Han}+?)</strong>.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.