Skip to content

Commit

Permalink
Glow: Add support Python's floor division operator. Fixes #212
Browse files Browse the repository at this point in the history
  • Loading branch information
tipiirai committed Feb 22, 2024
1 parent 671c930 commit 43302e2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 35 deletions.
6 changes: 3 additions & 3 deletions packages/glow/src/glow.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@


const MIXED_HTML = ['html', 'jsx', 'php', 'astro', 'nue', 'vue', 'svelte', 'hb']
const LINE_COMMENT = { clojure: ';;', lua: '--', python: '#' }
const PREFIXES = {'+': 'ins', '-': 'del', '>': 'dfn' }
const LINE_COMMENT = { clojure: ';;', lua: '--' }
const MARK = /(?)([^]+)\1/g // ALT + q
const NL = '\n'

const RESERVED = 'null|true|false|undefined|import|from|async|await|package|begin\
const WORDS = 'null|true|false|undefined|import|from|async|await|package|begin\
|interface|class|new|int|func|function|get|set|export|default|const|var|let\
|return|for|while|defer|if|then|fi|int|string|number|def|public|static|void\
|continue|break|switch|case|final|finally|try|catch|while|super|long|float\
Expand Down Expand Up @@ -36,7 +36,7 @@ const HTML_TAGS = [
{ tag: 'i', re: /[^\w ]/g },

// keyword
{ tag: 'strong', re: new RegExp(`\\b(${RESERVED})\\b`, 'gi'), not: ['html'] },
{ tag: 'strong', re: new RegExp(`\\b(${WORDS})\\b`, 'gi'), not: ['html'] },

// variable name
{ tag: 'b', re: /\b([a-z][\w\-]+)\s*[:=\(!\[]/gi },
Expand Down
6 changes: 3 additions & 3 deletions packages/glow/test/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,15 @@ delete :: Int -> [a] -> Maybe [a]
`

const PYTHON = `
# function definition
# Function definition
def find_square(num):
result = num * num
return result
'''
This is a multiline comment
'''
square = find_square(3)
square = find_square(3) // 2
print('Square:', square)
`
Expand Down Expand Up @@ -697,7 +697,7 @@ await renderPage([
{ title: 'TypeScript', code: TS, lang: 'ts', },
{ title: 'ZIG', code: ZIG, lang: 'zig', },

].filter(el => el.lang == 'nuemark')
].filter(el => el.lang == 'python')

)

Expand Down
39 changes: 10 additions & 29 deletions packages/glow/test/glow-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,18 @@
<body class="is-dark">

<div class="syntax ">
<header><h2>Nuemark</h2></header>
<pre glow><code language="nuemark"><span><i>---</i></span>
<span><b>title</b><i>:</i> Noel<i>'</i>s cringe content</span>
<span><dfn><b>description</b><i>:</i> Not much to say</dfn></span>
<span><b>draft</b><i>:</i> <strong>true</strong></span>
<span><i>---</i></span>
<header><h2>Python</h2></header>
<pre glow><code language="python"><span><sup># Function definition</sup></span>
<span><strong>def</strong> <b>find_square</b><i>(</i>num<i>)</i><i>:</i></span>
<span> <b>result</b> <i>=</i> num <i>*</i> num</span>
<span> <strong>return</strong> result</span>
<span></span>
<span><label># Lets get magical</label></span>
<span>I'm baby truffaut umami wolf small batch iceland</span>
<span>adaptogen. Iceland <b>**</b>chambray<b>**</b> raclette stumptown</span>
<span><sup>'''</sup></span>
<span><sup>This is a multiline comment</sup></span>
<span><sup>'''</sup></span>
<span><b>square</b> <i>=</i> <b>find_square</b><i>(</i><em>3</em><i>)</i> <i>/</i><i>/</i> <em>2</em></span>
<span></span>
<span><sup>// line comment here</sup></span>
<span><i>[</i><label>table</label> <b>head</b><i>=</i><em>"Foo | Bar | Baz"</em><i>]</i></span>
<span> - Content first | + | + | +</span>
<span> - Content collections | + | + | +</span>
<span> - Hot-reloading | + | + | +</span>
<span> - AI content generation | + | + | +</span>
<span></span>
<span><i>&gt;</i><sup> This is my blockquote right here</sup></span>
<span></span>
<span>[.<label>listbox</label>]</span>
<span> <b>*</b> Nothing here to see</span>
<span> <b>*</b> This one is a banger</span>
<span></span>
<span><em> ![Hello](/banger.png)</em></span>
<span></span>
<span><i>[</i><label>image</label> <b>loading</b><i>=</i><em>"eager"</em><i>]</i></span>
<span><dfn> <b>small</b><i>:</i> <em>"/img/explainer-tall.png"</em></dfn></span>
<span> <b>src</b><i>:</i> <em>"/img/explainer.png"</em></span>
<span> <b>hidden</b><i>:</i> <strong>true</strong></span>
<span> <b>width</b><i>:</i> <em>800</em></span></code></pre>
<span><b>print</b><i>(</i><em>'Square:'</em><i>,</i> square<i>)</i></span></code></pre>
</div>

</body>

0 comments on commit 43302e2

Please sign in to comment.