You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/developer/website-development.mdx
+12-12Lines changed: 12 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ For more elaborate changes, including adding new pages, you will need to clone t
19
19
20
20
## Editing the Handbook
21
21
22
-
The handbook is the most updated part of the website and it includes quite a bit of infrastructure to support writing pages that describe features in any or all of the target languages. The root of the handbook pages in the `packages/documentation` part of the repo. That directory has a useful [README file](https://github.com/lf-lang/website-lingua-franca/blob/main/packages/documentation/README.md) that describes the structure and provides instructions for inserting code examples in any target language and target-specific text within a body of target-independent text.
22
+
The handbook is the most updated part of the website and it includes quite a bit of infrastructure to support writing pages that describe features in any or all of the target languages. The root of the handbook pages is the `packages/documentation` part of the repo. That directory has a useful [README file](https://github.com/lf-lang/website-lingua-franca/blob/main/packages/documentation/README.md) that describes the structure and provides instructions for inserting code examples in any target language and target-specific text within a body of target-independent text.
23
23
24
24
## Infrastructure
25
25
@@ -37,16 +37,16 @@ For languages other than Lingua Franca, highlighting is handled by Prism, which
37
37
38
38
For Lingua Franca, highlighting is handled by [Shiki](https://github.com/shikijs/shiki). This is mainly because we only have TextMate grammar definition and it is not easy to convert from it to Prism.
39
39
40
-
Like Prism, we are running Shiki in browser and the code is updated in browser by React after it is highlighted. Shiki has a relatively large footprint, so its not necessarily encouraged to run in browsers. Yet running it in browser might help SEO and makes maintenance easier.
40
+
Like Prism, we are running Shiki in the browser, and the code is updated in the browser by React after it is highlighted. Shiki has a relatively large footprint, so its not necessarily encouraged to run in browsers. However, running it in browser might help SEO and makes maintenance easier.
41
41
42
-
The component we created is `ShikiLFHighlighter` in `src/components/ShikiLFHighlighter/index.tsx`. As Shiki highlights code asynchorously, the component will display the unhighlighted code first (for a very short period of time), and asynchronously update the HTML to be the one with highlighted code with React. This will not hurt SEO as the highlight will not be considered by search engines.
42
+
The component we created is `ShikiLFHighlighter` in `src/components/ShikiLFHighlighter/index.tsx`. As Shiki highlights code asynchronously, the component will display the unhighlighted code first (for a very short period of time), and then asynchronously update the HTML with highlighted code using React. This will not hurt SEO because the highlight will not be considered by search engines.
43
43
44
-
Upon loading the webpage, Shiki will be initialised in the browser, loading grammars of all target languages and Lingua Franca, as configured in `clientModules` section in `docusaurus.config.js` and `src/components/ShikiLFHighlighter/shikiloader.ts`.
44
+
Upon loading the webpage, Shiki will be initialised in the browser, loading grammars of all target languages and Lingua Franca, as configured in `clientModules` section in `docusaurus.config.js` and `src/components/ShikiLFHighlighter/shikiloader.ts`.
45
45
46
-
We further swizzled Docusaurus' `CodeBlock` to use `ShikiLFHighlighter` if the code language matches a pattern that indicates the code language is Lingua Franca, so using ``` notation in Markdown with language `lf` could give us the correct highlight result. You can check `src/theme/CodeBlock/index.js` for more details.
46
+
We further changed Docusaurus' `CodeBlock` to use `ShikiLFHighlighter` if the code language matches a pattern that indicates the code language is Lingua Franca, so using ``` notation in Markdown with language `lf` could give us the correct highlight result. You can check `src/theme/CodeBlock/index.js` for more details.
47
47
48
48
:::note
49
-
Unlike the custom syntax highlighter in our old website, without specifying `target C`, the highlighter will not be able to highlight target language code correctly as it lacks context - even if the language speficied is `lf-c`. This will be solved in future updates to the highlighter.
49
+
Unlike the custom syntax highlighter in our old website, without specifying `target C`, the highlighter will not be able to highlight target language code correctly as it lacks context - even if the language specified is `lf-c`. This will be solved in future updates to the highlighter.
50
50
:::
51
51
52
52
#### Syntaxes for Lingua Franca Syntax Highlighting
@@ -70,9 +70,9 @@ We have also created a bunch of useful utility components to aid the target sele
70
70
71
71
### Multi-Target Utilities
72
72
73
-
Our whole Multi-Target infrastructure is built on top of docusaurus' [Tabs](https://docusaurus.io/docs/markdown-features/tabs) component.
73
+
Our whole Multi-Target infrastructure is built on top of Docusaurus' [Tabs](https://docusaurus.io/docs/markdown-features/tabs) component.
74
74
75
-
In general, different targets are just a bunch of `Tab` components with `groupId='target-languages'`.
75
+
In general, different targets are just a bunch of `Tab` components with `groupId='target-languages'`.
76
76
77
77
#### LanguageSelector
78
78
The target selector, which appears on the top, is a `Tab` component with no content. It is defined in `src/components/LinguaFrancaMultiTargetUtils/LanguageSelector.tsx`.
@@ -150,7 +150,7 @@ Specifically - you MUST use `ShowIf` inside of a `ShowIfs`, and a `ShowIfs` MUST
150
150
</ShowIf>
151
151
</ShowIfs>
152
152
```
153
-
Where the target languages could be a subset of all targets which we support but must NOT collide.
153
+
Where the target languages could be a subset of all targets which we support but must NOT collide.
154
154
As long as you have more than one `ShowIf` inside you can have as many as you like.
155
155
156
156
##### Example
@@ -185,7 +185,7 @@ As long as you have more than one `ShowIf` inside you can have as many as you li
185
185
`ShowOnly` uses hacky Docusaurus-internal methods for the time being. To ensure better compatibility, you should prefer `ShowIf`.
186
186
:::
187
187
188
-
Sometimes, you want to display a piece of information only for one language. While you can use `ShowIfs` and one `ShowIf` inside of it, the issue people typically discover is that the rendered result looks miserable, because each `Tab` will add some sort of padding above and below it.
188
+
Sometimes, you want to display a piece of information only for one language. While you can use `ShowIfs` and one `ShowIf` inside of it, the issue people typically discover is that the rendered result looks miserable, because each `Tab` will add some sort of padding above and below it.
189
189
190
190
For this, we built `ShowOnly` which reads the selected tab from `@docusaurus/theme-common/internal/useTabs` and displays the information inside if the target selected matches, and the output is a `<div>` or a `<span>` so that it looks like it's blended in. This is hacky and could break any time if docusaurus decides to change how their `Tabs` work.
191
191
@@ -196,7 +196,7 @@ For this, we built `ShowOnly` which reads the selected tab from `@docusaurus/the
196
196
{/* Markdown contents */}
197
197
</ShowOnly>
198
198
```
199
-
Where the target languages could be a subset of all targets which we support.
199
+
Where the target languages could be a subset of all targets which we support.
200
200
If you include `inline` it will result in a `<span>`, if not, a `<div>`.
201
201
202
202
##### Examples
@@ -336,4 +336,4 @@ For docusaurus-related question, you should redirect your question to [them](htt
336
336
337
337
The LF syntax file is fetched [here](https://github.com/lf-lang/vscode-lingua-franca/blob/main/syntaxes/lflang.tmLanguage.json) and should be updated from time to time. If the syntax highlighting is not working properly, check the TextMate grammar, then check with [shiki](https://github.com/shikijs/shiki).
338
338
339
-
For website-specific utilities, you can open an issue on GitHub or [ask @axmmisaka directly](/community).
339
+
For website-specific utilities, you can open an issue on GitHub or [ask @axmmisaka directly](/community).
Copy file name to clipboardExpand all lines: src/components/LinguaFrancaMultiTargetUtils/DynamicMultiTargetCodeblock.tsx
+34Lines changed: 34 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,37 @@
1
+
/**
2
+
* #### DynamicMultiTargetCodeblock
3
+
*
4
+
* Warnings:
5
+
* - This is not working properly with versioning and will have issues with Webpack performance!
6
+
* - This is not working properly now! Need to fix the file path in `content` in `DynamicMultiTargetCodeblock.tsx`.
7
+
*
8
+
* This utility allows you to only supply a LF filename and all files will be dynamically imported. The issue is Webpack is not intelligent enough so if you use it, it will probably load all LF files in `assets`. Also, because relative import appears to be impossible, using it will always get you the latest code examples. See `src/components/LinguaFrancaMultiTargetUtils/DynamicMultiTargetCodeblock.tsx`.
9
+
*
10
+
* ##### Examples
11
+
*
12
+
* ```tsx
13
+
* <DynamicMultiTargetCodeblock c cpp ts rs py file="HelloWorld" />
14
+
* ```
15
+
*
16
+
* To suppress warnings, add
17
+
*
18
+
* ```tsx
19
+
* <DynamicMultiTargetCodeblock doNotTransformInMDX c cpp ts rs py file="HelloWorld" />
20
+
* ```
21
+
*
22
+
* #### DynamicMultiTargetCodeblock with TransformDynamicLFFileImportToStatic
23
+
*
24
+
* Warning: This is an experiment and should not be used in production!
25
+
*
26
+
* A way to make `DynamicMultiTargetCodeblock` more sane is to use remark and preprocess it into a bunch of import statements and a `NoSelectorTargetCodeBlock`.
27
+
*
28
+
* `src/remark/TransformDynamicLFFileImportToStatic.ts` is a remark plugin that does so. It looks like a disaster and I don't understand it anymore 5 months after writing it.
29
+
*
30
+
* To use DynamicMultiTargetCodeBlock, add it to `docusaurus.config.ts` as a ReMark preprocessor.
0 commit comments