Skip to content

Conversation

@ivanzhangwb
Copy link

@ivanzhangwb ivanzhangwb commented Dec 14, 2025

Summary
Added optional Chinese font support for the Pandoc converter, enabling proper rendering of Chinese characters in
Markdown to PDF conversions.

Changes

Environment Variables (src/helpers/env.ts)

  • PANDOC_ENABLE_CHINESE_FONT: Enable/disable Chinese font support
  • PANDOC_CHINESE_FONT_PATH: Path to Chinese font files
  • PANDOC_CHINESE_FONT_FAMILY: Chinese font family name (default: SimSun)

Pandoc Converter Enhancement (src/converters/pandoc.ts)

  • Automatically detects and applies Chinese font configuration when converting to PDF/LaTeX formats
  • Adds Chinese font parameters when using XeLaTeX engine
  • Supports custom font paths and font families

Docker Configuration Example (compose.yaml)

  • Added Chinese font-related environment variable examples
  • Provided font file mounting configuration template

Usage

  1. Enable Chinese font support:
    1 environment:
    2 - PANDOC_ENABLE_CHINESE_FONT=true
    3 - PANDOC_CHINESE_FONT_FAMILY=NotoSansCJK

  2. Mount host font files:
    1 volumes:
    2 - /usr/share/fonts/truetype/chinese:/usr/share/fonts/truetype/chinese:ro

Testing Recommendations
Test the following scenarios:

  • Chinese Markdown to PDF conversion
  • Rendering effects of different Chinese fonts
  • Correctness of environment variable configuration
  • Test source file: markdown TestChinese.md and pdf TestChinese.pdf

This improvement enhances ConvertX's friendliness for Chinese users while maintaining code simplicity and
maintainability.


Summary by cubic

Added optional Chinese font support for Pandoc PDF/LaTeX conversions so Chinese text renders correctly. Controlled via environment variables and disabled by default.

  • New Features

    • Pandoc adds XeLaTeX font settings when enabled.
    • Env vars: PANDOC_ENABLE_CHINESE_FONT, PANDOC_CHINESE_FONT_PATH, PANDOC_CHINESE_FONT_FAMILY (default: SimSun).
    • Dockerfile installs common Chinese font packages, initializes font cache, and sets zh_CN.UTF-8 locale; compose examples show font volume mount and env usage.
  • Migration

    • Set PANDOC_ENABLE_CHINESE_FONT=true.
    • Optionally set PANDOC_CHINESE_FONT_FAMILY and PANDOC_CHINESE_FONT_PATH.
    • Mount host fonts into the container if needed (read-only).

Written for commit 498a35b. Summary will update automatically on new commits.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 issues found across 5 files

Prompt for AI agents (all 4 issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="docker-compose.yml">

<violation number="1" location="docker-compose.yml:9">
P1: Hardcoded JWT_SECRET with a real-looking value is a security risk. Users may copy this directly into production. Use a clearly-marked placeholder like the existing `compose.yaml` uses (`aLongAndSecretStringUsedToSignTheJSONWebToken1234`) or reference an external secret.</violation>
</file>

<file name="compose.yaml">

<violation number="1" location="compose.yaml:21">
P3: The comment is misleading - this environment variable specifies the font path inside the container, not on the host. The volume mount (line above) handles mapping host fonts to the container path. Consider changing the comment to clarify this is the container path.</violation>
</file>

<file name="Dockerfile">

<violation number="1" location="Dockerfile:77">
P2: Trailing whitespace after backslash line continuation characters. While this may work in many shells, it&#39;s considered bad practice and can cause issues. Remove trailing spaces after the `\` characters.</violation>

<violation number="2" location="Dockerfile:87">
P1: Incorrect font path: `fonts-noto-cjk` installs to `/usr/share/fonts/opentype/noto/`, not `/usr/share/fonts/truetype/noto/`. The symlink will point to a non-existent directory.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Ask questions if you need clarification on any suggestion

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

ports:
- "3001:3000"
environment:
- JWT_SECRET=ivanzhangwb # will use randomUUID() if unset
Copy link

@cubic-dev-ai cubic-dev-ai bot Dec 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Hardcoded JWT_SECRET with a real-looking value is a security risk. Users may copy this directly into production. Use a clearly-marked placeholder like the existing compose.yaml uses (aLongAndSecretStringUsedToSignTheJSONWebToken1234) or reference an external secret.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At docker-compose.yml, line 9:

<comment>Hardcoded JWT_SECRET with a real-looking value is a security risk. Users may copy this directly into production. Use a clearly-marked placeholder like the existing `compose.yaml` uses (`aLongAndSecretStringUsedToSignTheJSONWebToken1234`) or reference an external secret.</comment>

<file context>
@@ -0,0 +1,16 @@
+    ports:
+      - &quot;3001:3000&quot;
+    environment:
+      - JWT_SECRET=ivanzhangwb # will use randomUUID() if unset
+      - HTTP_ALLOWED=true # uncomment this if accessing it over a non-https connection
+      - PANDOC_ENABLE_CHINESE_FONT=true
</file context>

✅ Addressed in 695a17a

compose.yaml Outdated
- TZ=Europe/Stockholm # set your timezone, defaults to UTC
# - UNAUTHENTICATED_USER_SHARING=true # for use with ALLOW_UNAUTHENTICATED=true to share history with all unauthenticated users / devices
# - PANDOC_ENABLE_CHINESE_FONT=true # enable Chinese font support for Pandoc PDF/LaTeX conversion
# - PANDOC_CHINESE_FONT_PATH=/usr/share/fonts/truetype/chinese # path to Chinese font directory on host
Copy link

@cubic-dev-ai cubic-dev-ai bot Dec 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The comment is misleading - this environment variable specifies the font path inside the container, not on the host. The volume mount (line above) handles mapping host fonts to the container path. Consider changing the comment to clarify this is the container path.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At compose.yaml, line 21:

<comment>The comment is misleading - this environment variable specifies the font path inside the container, not on the host. The volume mount (line above) handles mapping host fonts to the container path. Consider changing the comment to clarify this is the container path.</comment>

<file context>
@@ -16,5 +17,8 @@ services:
       - TZ=Europe/Stockholm # set your timezone, defaults to UTC
       # - UNAUTHENTICATED_USER_SHARING=true # for use with ALLOW_UNAUTHENTICATED=true to share history with all unauthenticated users / devices
+      # - PANDOC_ENABLE_CHINESE_FONT=true # enable Chinese font support for Pandoc PDF/LaTeX conversion
+      # - PANDOC_CHINESE_FONT_PATH=/usr/share/fonts/truetype/chinese # path to Chinese font directory on host
+      # - PANDOC_CHINESE_FONT_FAMILY=NotoSansCJK # Chinese font family name
     ports:
</file context>
Suggested change
# - PANDOC_CHINESE_FONT_PATH=/usr/share/fonts/truetype/chinese # path to Chinese font directory on host
# - PANDOC_CHINESE_FONT_PATH=/usr/share/fonts/truetype/chinese # path to Chinese font directory in container (mount fonts via volumes above)

✅ Addressed in 695a17a

Dockerfile Outdated
texlive-latex-extra \
texlive-latex-recommended \
texlive-xetex \
texlive-lang-chinese \
Copy link

@cubic-dev-ai cubic-dev-ai bot Dec 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Trailing whitespace after backslash line continuation characters. While this may work in many shells, it's considered bad practice and can cause issues. Remove trailing spaces after the \ characters.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At Dockerfile, line 77:

<comment>Trailing whitespace after backslash line continuation characters. While this may work in many shells, it&#39;s considered bad practice and can cause issues. Remove trailing spaces after the `\` characters.</comment>

<file context>
@@ -74,9 +74,19 @@ RUN apt-get update &amp;&amp; apt-get install -y \
   texlive-latex-extra \
   texlive-latex-recommended \
   texlive-xetex \
+  texlive-lang-chinese \         
+  fonts-noto-cjk \               
+  fonts-wqy-zenhei \             
</file context>
Suggested change
texlive-lang-chinese \
texlive-lang-chinese \

✅ Addressed in 695a17a

Dockerfile Outdated
&& rm -rf /var/lib/apt/lists/*

RUN mkdir -p /usr/share/fonts/truetype/chinese && \
ln -sf /usr/share/fonts/truetype/noto /usr/share/fonts/truetype/chinese/noto && \
Copy link

@cubic-dev-ai cubic-dev-ai bot Dec 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Incorrect font path: fonts-noto-cjk installs to /usr/share/fonts/opentype/noto/, not /usr/share/fonts/truetype/noto/. The symlink will point to a non-existent directory.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At Dockerfile, line 87:

<comment>Incorrect font path: `fonts-noto-cjk` installs to `/usr/share/fonts/opentype/noto/`, not `/usr/share/fonts/truetype/noto/`. The symlink will point to a non-existent directory.</comment>

<file context>
@@ -74,9 +74,19 @@ RUN apt-get update &amp;&amp; apt-get install -y \
   &amp;&amp; rm -rf /var/lib/apt/lists/*
 
+RUN mkdir -p /usr/share/fonts/truetype/chinese &amp;&amp; \
+    ln -sf /usr/share/fonts/truetype/noto /usr/share/fonts/truetype/chinese/noto &amp;&amp; \
+    fc-cache -f -v
+  
</file context>
Suggested change
ln -sf /usr/share/fonts/truetype/noto /usr/share/fonts/truetype/chinese/noto && \
ln -sf /usr/share/fonts/opentype/noto /usr/share/fonts/truetype/chinese/noto && \

✅ Addressed in 695a17a

@C4illin
Copy link
Owner

C4illin commented Dec 14, 2025

Nice! Is it possible to configure it in any way so that it automatically uses a CJK font when needed, so not everyone have to configure it? I think that would be extremely nice, but no worries if not :)

@ivanzhangwb
Copy link
Author

Nice! Is it possible to configure it in any way so that it automatically uses a CJK font when needed, so not everyone have to configure it? I think that would be extremely nice, but no worries if not :)

Thanks for the feedback! Auto-switching for CJK fonts would be very convenient. Currently, it still needs to be manually enabled, as I haven't yet implemented reliable detection for CJK content in source files. 😅 . I'll keep this in mind for future improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants