-
-
Notifications
You must be signed in to change notification settings - Fork 567
Add client-side rendering option for Markdown pane based on MyST #7149
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
Draft
philippjfr
wants to merge
6
commits into
main
Choose a base branch
from
myst-pane
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f4b1cc2
Add a MyST pane
philippjfr ca754de
Cleanup
philippjfr dbe7b3a
Fold mystjs renderer into Markdown pane
philippjfr b075903
Remove empty line
philippjfr d5b8e87
Switch to parser and html converter
philippjfr 3ac9842
Apply suggestions from code review
philippjfr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| from ..config import config | ||
| from ..io.resources import bundled_files | ||
| from ..util import classproperty | ||
| from .markup import HTML | ||
|
|
||
|
|
||
| class MyST(HTML): | ||
| """ | ||
| A bokeh model to render MyST markdown on the client side | ||
| """ | ||
|
|
||
| __javascript_module_exports__ = ['* as mystparser', '* as myst2html'] | ||
|
|
||
| __javascript_modules_raw__ = [ | ||
| f"{config.npm_cdn}/[email protected]/+esm", | ||
| f"{config.npm_cdn}/[email protected]/+esm" | ||
| ] | ||
|
|
||
| @classproperty | ||
| def __javascript_modules__(cls): | ||
| return bundled_files(cls, 'javascript_modules') | ||
|
|
||
| __javascript_raw__ = [ | ||
| 'https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js' | ||
| ] | ||
|
|
||
| @classproperty | ||
| def __javascript__(cls): | ||
| return bundled_files(cls) | ||
|
|
||
| __css_raw__ = [ | ||
| 'https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/github-dark.min.css' | ||
| ] | ||
|
|
||
| @classproperty | ||
| def __css__(cls): | ||
| return bundled_files(cls, 'css') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import type * as p from "@bokehjs/core/properties" | ||
| import {HTMLView, HTML} from "./html" | ||
|
|
||
| export class MySTView extends HTMLView { | ||
| declare model: MyST | ||
|
|
||
| override set_html(html: string | null): void { | ||
| super.set_html(html) | ||
| for (const el of this.container.querySelectorAll("pre code")) { | ||
| (window as any).hljs.highlightElement(el) | ||
| } | ||
| } | ||
|
|
||
| override process_tex(): string { | ||
| const parsed = (window as any).mystparser.mystParse(this.model.text) | ||
| const text = (window as any).myst2html.mystToHtml(parsed) | ||
| if (this.model.disable_math || !this.contains_tex(text)) { | ||
| return text | ||
| } | ||
|
|
||
| const tex_parts = this.provider.MathJax.find_tex(text) | ||
| const processed_text: string[] = [] | ||
|
|
||
| let last_index: number | undefined = 0 | ||
| for (const part of tex_parts) { | ||
| processed_text.push(text.slice(last_index, part.start.n)) | ||
| processed_text.push(this.provider.MathJax.tex2svg(part.math, {display: part.display}).outerHTML) | ||
|
|
||
| last_index = part.end.n | ||
| } | ||
|
|
||
| if (last_index! < text.length) { | ||
| processed_text.push(text.slice(last_index)) | ||
| } | ||
|
|
||
| return processed_text.join("") | ||
| } | ||
| } | ||
|
|
||
| export namespace MyST { | ||
| export type Attrs = p.AttrsOf<Props> | ||
| export type Props = HTML.Props | ||
| } | ||
|
|
||
| export interface MyST extends MyST.Attrs {} | ||
|
|
||
| export class MyST extends HTML { | ||
| declare properties: MyST.Props | ||
|
|
||
| constructor(attrs?: Partial<MyST.Attrs>) { | ||
| super(attrs) | ||
| } | ||
|
|
||
| static override __module__ = "panel.models.myst" | ||
|
|
||
| static { | ||
| this.prototype.default_view = MySTView | ||
| this.define<MyST.Props>(({}) => ({})) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.