Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add presets #1964

Draft
wants to merge 2 commits into
base: next
Choose a base branch
from
Draft

feat: add presets #1964

wants to merge 2 commits into from

Conversation

Mister-Hope
Copy link
Member

No description provided.

@Mister-Hope Mister-Hope marked this pull request as draft May 9, 2023 08:42
@Mister-Hope Mister-Hope changed the base branch from main to next May 9, 2023 08:42
@Mister-Hope
Copy link
Member Author

Mister-Hope commented May 9, 2023

@lizheming Looking forward for your feedback about this.

To decouple function based feature, I am a planning to create a new concept called presets and split the whole renderer and capatcha features out of client package.

Shiki highlighter needs an async loading stage, so it's a bit hacky and I am not adding it now.

My current plan is to mark client-presets as private, and release each presets as a single package with it's name, e.g.:

  • @waline/recapcha-v3
  • @waline/marked-slim
  • @waline/markdown-it-emoji-katex-prism
  • ...

As each bundle may be around MBs (with tex support), so it would be better to release them as separate packages.

But with amounts of preset package, I think maybe it could be better to create a walinejs/presets repo for it?

Looking forward for your opinion.

@Mister-Hope
Copy link
Member Author

Mister-Hope commented May 9, 2023

Besides, another plan is to release some sperate function helpers and let users combine them. This would be complicated than presets, but easier to maintain,

For example, we release @waline/katex and @waline/mathjax to provide a unify api texRenderer, and we provide @waline/markdown-it-renderer and @waline/marked-render with export path /emoji /tex and /highlight available, and users should do the following themselves:

import { texRenderer } from '@waline/katex';
import { highlighter } from '@waline/highlightjs'
import { markdownIt } from '@waline/markdown-it-renderer';
import { emoji } from '@waline/markdown-it-renderer/emoji';
import { tex } from '@waline/markdown-it-renderer/tex';

const initRenderer = ({ emojiMap }) => {
  markdownIt.use(tex, texRenderer);
  markdownIt.use(emoji, emojiMap);
  markdownIt.options.highlight = highlighter;

 return (content) => markdownIt.render(content);
}

Another case:

import { texRenderer } from '@waline/mathjax';
import { highlighter, prepareHighlighter } from '@waline/shiki'
import { marked } from '@waline/marked-renderer';
import { markedEmoji } from '@waline/marked-renderer/emoji';
import { markedHighlight } from '@waline/marked-renderer/highlighter';
import { markedTex } from '@waline/marked-renderer/tex';

const initRenderer = async ({ emojiMap }) => {
  await prepareHighlighter();
  marked.use(markedTex(texRenderer));
  marked.use(markedEmoji (emojiMap));
  marked.use(markedHighlight({ highlight: highlighter }));


 return (content) => marked.parse(content);
}

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.

1 participant