Skip to content

Commit

Permalink
deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Aug 21, 2023
0 parents commit 44110a1
Show file tree
Hide file tree
Showing 14 changed files with 10,474 additions and 0 deletions.
50 changes: 50 additions & 0 deletions browser/browser.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
* { font-family: Arial; }
a { text-decoration: none; }
body { background-color: #DDDDDD; }
h1 {
text-align: center;
font-size: 108px;
color: #363636;
margin: 2%;
}
h2 {
text-align: center;
font-size: 64px;
color: #404040;
margin: 2%;
}
h3 {
font-size: 28px;
margin: 1% 10%;
}
h4 {
font-size: 20px;
color: #202020;
margin: 1% 10%;
}
p, li {
font-size: 18px;
color: #232323;
}
li img {
height: 1em;
width: auto;
}
pre, code { font-family: Consolas; }
body > * {
margin-left: 0;
margin-right: 0;
}
#output > * {
margin-left: 10%;
margin-right: 10%;
}
textarea {
font-family: Consolas;
display: block;
width: 100%;
}
#head {
margin-left: 10%;
margin-right: 10%;
}
25 changes: 25 additions & 0 deletions browser/converter.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<html>
<head>
<script type="text/javascript" src="converter.js"></script>
<meta charset="utf-8">
<meta http-equiv="Content-Language" content="en-us">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="browser.css">
<title>margrave converter</title>
<!--<link rel="shortcut icon" type="image/png" href="margrave.png">-->
</head>
<body>
<h2>margrave converter</h2>
<div id="head">
<textarea id="input" rows="15"></textarea>
<a href="reference.html">Reference</a>
<button id="convert" onclick="convert();">Convert</button>
<button id="convert-to-source" onclick="convertToSource();">Convert to source</button>
<button id="download" onclick="download();">Convert and download</button>
Filename:
<input type="text" id="filename" style="display:inline" placeholder="Filename">
</div>
<div id="output"></div>
</body>
</html>
6,428 changes: 6,428 additions & 0 deletions browser/converter.js

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions browser/converter.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import ../src/[margrave, margrave/common, margrave/element], dom

proc convertMargrave(text: NativeString): NativeString =
result = ""
for elem in parseMargrave(text):
result.add(toNativeString(elem))
result.add(NativeString("\n"))

proc input(): cstring =
getElementById("input").value

proc convert() {.exportc.} =
let input = input()
let output = convertMargrave(input)
getElementById("output").innerHTML = output

proc convertToSource() {.exportc.} =
let input = input()
let output = convertMargrave(input)
let sourceBlock = document.createElement("pre")
sourceBlock.textContent = output
let outputElement = getElementById("output")
outputElement.innerHTML = ""
outputElement.appendChild(sourceBlock)

proc filename(): cstring =
proc `or`(x, y: cstring): cstring {.importjs: "# || #".}
getElementById("filename").value or "output.html"

proc download() {.exportc.} =
let input = input()
let output = convertMargrave(input)

proc blobHtml(str: cstring): Blob {.importjs: "new Blob([#], {type: 'text/html'})", constructor.}
proc createUrl(blob: Blob): cstring {.importc: "window.URL.createObjectURL".}
proc revokeUrl(url: cstring) {.importc: "window.URL.revokeObjectURL".}

let blob = blobHtml(output)
let url = createUrl(blob)
let a = document.createElement("a")
a.style.display = "none"
a.setAttr("href", url)
a.setAttr("download", filename())
document.body.appendChild(a)
a.click()
revokeUrl(url)
document.body.removeChild(a)
3 changes: 3 additions & 0 deletions browser/converter.nims
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--backend:js
switch("path", ".")
switch("d", "danger") # doesnt do anything, have to do it manually via command
143 changes: 143 additions & 0 deletions browser/reference.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Language" content="en-us">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="browser.css">
<title>Margrave Reference</title>
<style>
.column {
float: left;
width: 50%;
}
.row:after {
content: "";
display: table;
clear: both;
}
</style>
<!--<link rel="shortcut icon" type="image/png" href="margrave.png">-->
</head>
<body>
<p>this page is a bit broken right now</p>
<div class="row">
<div class="column">
<pre>
To escape use \\

# Heading1
## Heading2
### Heading3
#### Heading4
##### Heading5
###### Heading6

####{heading-id} Heading (new, makes heading-id the id of this heading)

* Bullet points
+ Plus
- Minus

1. Numbered list
2. Can be
4. Any number
. or just a dot (new),
can also indent

&gt; Blockquotes
&gt;
&gt; can _be_ **formatted**

```
Code blocks
Have no formatting

HTML &amp; chars &lt; automatically &gt; escaped
```

Inline formatting:

Link: [text](url)
[text **can have formatting**](url "tooltip text")
Image: ![](url)
![alt text (image doesnt load)](url "tooltip text")
Superscript (new): 4^(3) = 64
Subscript (new): a[n] = 2n + 1
Bold: **text**
Underline: __text__
italic: *text* _text_
Strikethrough: ~~text~~
Inline code (has formatting!): `text`
Checkboxes anywhere in the document, not just lists: [ ] [x]
Raw text with curly braces (new): {aaaa **aa** &lt;span&gt;angle brackets not escaped for raw HTML&lt;/span&gt;}
Nested curly braces: {aa {bb} cc {dd {ee}} ff}
Inline code without formatting, can escape HTML chars: `{1 \&lt; 3 ? _ * 3 + 3 * _ + 2 ** 2 ** 2 : 4 \&amp; 2}`

Inline HTML (no formatting inside): &lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;a 1&lt;/td&gt;
&lt;td&gt;a 2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;b 1&lt;/td&gt;
&lt;td&gt;b 2&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
</pre>
</div>
<div class="column">
<p>To escape use \</p>
<h1> Heading1</h1>
<h2> Heading2</h2>
<h3> Heading3</h3>
<h4> Heading4</h4>
<h5> Heading5</h5>
<h6> Heading6</h6>
<h4 id="heading-id"> Heading (new, makes heading-id the id of this heading)</h4>
<ul><li>Bullet points</li><li>Plus</li><li>Minus</li></ul>
<ol><li> Numbered list</li><li> Can be</li><li> Any number</li><li> or just a dot (new),
can also indent</li></ol>
<blockquote><p> Blockquotes</p>

<p> can <em>be</em> <strong>formatted</strong></p></blockquote>
<pre>Code blocks
Have no formatting

HTML &amp; chars &lt; automatically &gt; escaped
</pre>
<p>Inline formatting:</p>
<p>Link: <a href="url">text</a>
<a href="url" title="tooltip text">text <strong>can have formatting</strong></a>
Image: <img src="url">
<img src="url" alt="alt text (image doesnt load)" title="tooltip text">
Superscript (new): 4<sup>3</sup> = 64
Subscript (new): a<sub>n</sub> = 2n + 1
Bold: <strong>text</strong>
Underline: <u>text</u>
italic: <em>text</em> <em>text</em>
Strikethrough: <s>text</s>
Inline code (has formatting!): <code>text</code>
Checkboxes anywhere in the document, not just lists: <input type="checkbox" disabled> <input type="checkbox" disabled checked>
Raw text with curly braces (new): aaaa **aa** <span>angle brackets not escaped for raw HTML</span>
Nested curly braces: aa {bb} cc {dd {ee}} ff
Inline code without formatting, can escape HTML chars: <code>1 &lt; 3 ? _ * 3 + 3 * _ + 2 ** 2 ** 2 : 4 &amp; 2</code></p>
<p>Inline HTML (no formatting inside): <table>
<tbody>
<tr>
<td>a 1</td>
<td>a 2</td>
</tr>
<tr>
<td>b 1</td>
<td>b 2</td>
</tr>
</tbody>
</table>
</p>
</div>
</div>
</body>
</html>
Loading

0 comments on commit 44110a1

Please sign in to comment.