langium-railroad
Advanced tools
Comparing version 2.1.0 to 3.0.0-next.79e4301
@@ -6,3 +6,4 @@ /****************************************************************************** | ||
******************************************************************************/ | ||
import { EOL, GrammarAST, expandToString, findNameAssignment } from 'langium'; | ||
import { GrammarAST, findNameAssignment } from 'langium'; | ||
import { expandToStringLF, expandToStringLFWithNL } from 'langium/generate'; | ||
import { default as rr } from 'railroad-diagrams'; | ||
@@ -35,10 +36,12 @@ export const defaultCss = ` | ||
function styling(options) { | ||
return expandToString ` | ||
<style> | ||
${defaultCss} | ||
</style> | ||
${(options === null || options === void 0 ? void 0 : options.css) ? expandToString ` | ||
<style> | ||
${options.css.trim()} | ||
</style>` : ''}`; | ||
return expandToStringLF ` | ||
<style> | ||
${defaultCss} | ||
</style> | ||
${(options === null || options === void 0 ? void 0 : options.css) ? expandToStringLF ` | ||
<style> | ||
${options.css.trim()} | ||
</style> | ||
` : ''} | ||
`; | ||
} | ||
@@ -55,16 +58,16 @@ /** | ||
export function createGrammarDiagramHtml(rules, options) { | ||
let text = `<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
${styling(options)}${(options === null || options === void 0 ? void 0 : options.javascript) ? ` | ||
<script> | ||
${options.javascript} | ||
</script>` : ''} | ||
</head> | ||
<body> | ||
`; | ||
text += createGrammarDiagram(rules); | ||
text += `</body> | ||
</html>`; | ||
return text; | ||
return expandToStringLFWithNL ` | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
${styling(options)}${(options === null || options === void 0 ? void 0 : options.javascript) ? ` | ||
<script> | ||
${options.javascript} | ||
</script>` : ''} | ||
</head> | ||
<body> | ||
${createGrammarDiagram(rules)} | ||
</body> | ||
</html> | ||
`; | ||
} | ||
@@ -96,3 +99,3 @@ /** | ||
for (const nonTerminal of rules) { | ||
text.push('<h2 class="non-terminal-name">', nonTerminal.name, '</h2>', EOL, createRuleDiagram(nonTerminal)); | ||
text.push('<h2 class="non-terminal-name">', nonTerminal.name, '</h2>', '\n', createRuleDiagram(nonTerminal)); | ||
} | ||
@@ -99,0 +102,0 @@ return text.join(''); |
{ | ||
"name": "langium-railroad", | ||
"version": "2.1.0", | ||
"version": "3.0.0-next.79e4301", | ||
"description": "Use Langium as source for railroad syntax diagrams", | ||
@@ -37,3 +37,3 @@ "homepage": "https://langium.org", | ||
"dependencies": { | ||
"langium": "~2.1.0", | ||
"langium": "3.0.0-next.79e4301", | ||
"railroad-diagrams": "~1.0.0" | ||
@@ -40,0 +40,0 @@ }, |
@@ -0,0 +0,0 @@ # Langium Railroad Diagrams |
@@ -7,3 +7,4 @@ /****************************************************************************** | ||
import { EOL, GrammarAST, expandToString, findNameAssignment } from 'langium'; | ||
import { GrammarAST, findNameAssignment } from 'langium'; | ||
import { expandToStringLF, expandToStringLFWithNL } from 'langium/generate'; | ||
import type { FakeSVG } from 'railroad-diagrams'; | ||
@@ -44,10 +45,12 @@ import { default as rr } from 'railroad-diagrams'; | ||
function styling(options?: GrammarDiagramOptions) { | ||
return expandToString` | ||
<style> | ||
${defaultCss} | ||
</style> | ||
${options?.css ? expandToString` | ||
<style> | ||
${options.css.trim()} | ||
</style>` : ''}`; | ||
return expandToStringLF` | ||
<style> | ||
${defaultCss} | ||
</style> | ||
${options?.css ? expandToStringLF` | ||
<style> | ||
${options.css.trim()} | ||
</style> | ||
` : ''} | ||
`; | ||
} | ||
@@ -65,17 +68,16 @@ | ||
export function createGrammarDiagramHtml(rules: GrammarAST.ParserRule[], options?: GrammarDiagramOptions): string { | ||
let text = `<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
${styling(options)}${options?.javascript ? ` | ||
<script> | ||
${options.javascript} | ||
</script>` : ''} | ||
</head> | ||
<body> | ||
`; | ||
text += createGrammarDiagram(rules); | ||
text += `</body> | ||
</html>`; | ||
return text; | ||
return expandToStringLFWithNL` | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
${styling(options)}${options?.javascript ? ` | ||
<script> | ||
${options.javascript} | ||
</script>` : ''} | ||
</head> | ||
<body> | ||
${createGrammarDiagram(rules)} | ||
</body> | ||
</html> | ||
`; | ||
} | ||
@@ -110,3 +112,3 @@ | ||
for (const nonTerminal of rules) { | ||
text.push('<h2 class="non-terminal-name">', nonTerminal.name, '</h2>', EOL, createRuleDiagram(nonTerminal)); | ||
text.push('<h2 class="non-terminal-name">', nonTerminal.name, '</h2>', '\n', createRuleDiagram(nonTerminal)); | ||
} | ||
@@ -113,0 +115,0 @@ return text.join(''); |
@@ -0,0 +0,0 @@ /****************************************************************************** |
@@ -0,0 +0,0 @@ /****************************************************************************** |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
28137
535
2
1
+ Addedlangium@3.0.0-next.79e4301(transitive)
- Removedlangium@2.1.3(transitive)
Updatedlangium@3.0.0-next.79e4301