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

Make example.html work again. Not the prettiest technique, but it works. #109

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from

Conversation

RossPatterson
Copy link
Contributor

Fixes #97.

I have a fix for this, but IMHO, it's ugly. The inability to run a <script type=module> synchronously with the page load makes it hard to get the railroad.js functions into a place where the diagram scripts can access them reliably. And the inability of an ES module script, even an inline one, to get document.currentScript, or to locate itself in the DOM, makes it hard to figure out where to insert the diagram SVGs.

My changes entail wrapping each <script> tag in a new <div>, and monkey-patching Diagram.addTo() to locate the appropriate <script> tag using a way that will work for example.html, even if it can't be generalized to other uses. Doing it this way buries the ugliness where nobody will see it when they're looking at the browser results (as opposed to the contents of the example.html file). Which is lame, but it works. Doing so results in examples that are coded like this:

<h1 id='ident'>IDENT</h1>
<div>
<script type=module>
ComplexDiagram(
	Choice(0, Skip(), '-'),
	Choice(0, NonTerminal('name-start char'), NonTerminal('escape')),
	ZeroOrMore(
		Choice(0, NonTerminal('name char'), NonTerminal('escape')))).addTo();
</script>
</div>

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.

example.html has bit-rotted
1 participant