High Lighting all TrimPres in a Page
High lighting a certain source code is simple. However, when we need to high light all source coeds in a page, the situations are rather complexed. The following situations should be taken into account:
- high lighting different source codes
- deciding when and how to set a default language
- high lighting while running the codes
- the safe importing different modules without conflicts
- auto-responding to the switch of color theme
This page would embrace all of these situations to test our implementations work well.
Simple Usage
A line of codes would suffice to handle all situations:
Basic trimpre
For a normal trim-pre, its' language would be decided by highlihgt.js automatically.
A CSS content:
JavaScript codes seems OK most of time.
Sepcify a default language
Unexpected result for some Python codes:
If found, we can set a default language for the codes above to avoid the side-effect of auto-decided:
And the result:
Markdown is supported, yet an explicit specifying of language is needed:
PageConsoles
We set each of trim-pre which has the class of auto-pageconsole
with the default language of javascript
.
A pageconsole:
A pageconsole with extra-src attribute:
Another pageconsole:
By default, there are no default styles for HTML tags.
| 1 | 2 |
This feature is useful if we want to set all initial CSS values from scratch.
By setting a use-predefined-styles attribute, we can use the pre-defined styles based on color schemes.
| 1 | 2 |
Runnable Wasm codes
When a trim-pre has the class of auto-wabt
,WabtUtils would be imported automatically, among with pc.
Runnable Python codes
Where a trim-pre has the class of auto-brython
,its' codes would be treated as Python and run.
Rendering Mermaid Codes
And auto-mermaid
to render Mermaid sources.
Implicit flowchart:
By now, Mermaid sources is not supported by highlight.js, so we adopt the CSS syntax to add little bit colors.
Explicit flowchart:
Sequence diagram:
Class diagram:
State diagram:
Mindmap:
QuadrantChart:
Rendering Graphviz Codes
A simple graph.
And for record nodes.
Hiding Sources
When rendering Graphviz or Mermaid diagrams, sometimes we need only the graph result, but not showing the sources. Then add a hide-srcs
to its' class attribute.
In this way we get a plain image.
Color Theme Handling
When the color theme is changed, both of the sources and result panel of each trim-pre, would respond automatically.
Click on the moon | sun icon at the top-right corner of this page to view the effects.
Conclusion
By importing only a line of codes, various trim-pres would be high-lighted, and JavaScript, Wasm, Python, Mermaid and Graphviz codes in each of them would be run automatically by setting the prefix auto-
to its class.
Each trim-pre behaves little bit like a cell of Jupyter Notebook, while keeping all source codes of each limited in its' own scope, without polluting the global scope.
So in the Web environment, I'd prefer to trim-pre rather than Jupyter Notebook.
In the future, more programming languages would be supported and integrated into trim-pre.
Extentions
See also:
