Skip to content

Commit

Permalink
[haskell-literate mode] Integrate
Browse files Browse the repository at this point in the history
Issue #3730
  • Loading branch information
marijnh committed Dec 29, 2015
1 parent 4955e6e commit 07bcf88
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
1 change: 1 addition & 0 deletions doc/compress.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ <h2>Script compression helper</h2>
<option value="http://codemirror.net/mode/haml/haml.js">haml.js</option>
<option value="http://codemirror.net/mode/handlebars/handlebars.js">handlebars.js</option>
<option value="http://codemirror.net/mode/haskell/haskell.js">haskell.js</option>
<option value="http://codemirror.net/mode/haskell-literate/haskell-literate.js">haskell-literate.js</option>
<option value="http://codemirror.net/mode/haxe/haxe.js">haxe.js</option>
<option value="http://codemirror.net/mode/htmlembedded/htmlembedded.js">htmlembedded.js</option>
<option value="http://codemirror.net/mode/htmlmixed/htmlmixed.js">htmlmixed.js</option>
Expand Down
27 changes: 16 additions & 11 deletions mode/haskell-literate/haskell-literate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,35 @@
else // Plain browser env
mod(CodeMirror)
})(function (CodeMirror) {
CodeMirror.defineMode("haskell-literate", function (config) {
var haskellMode = CodeMirror.getMode(config, "haskell")
"use strict"

CodeMirror.defineMode("haskell-literate", function (config, parserConfig) {
var baseMode = CodeMirror.getMode(config, (parserConfig && parserConfig.base) || "haskell")

return {
startState: function () {
return {
haskellCode: false,
haskellState: CodeMirror.startState(haskellMode)
inCode: false,
baseState: CodeMirror.startState(baseMode)
}
},
token: function (stream, state) {
if ((stream.sol() && stream.next() == '>') || state.haskellCode) {
state.haskellCode = true
return haskellMode.token(stream, state.haskellState)
if (stream.sol()) {
if (state.inCode = stream.eat(">"))
return "meta"
}
if (state.inCode) {
return baseMode.token(stream, state.baseState)
} else {
stream.skipToEnd()
return "comment"
}
},
blankLine: function (state) {
state.haskellCode = false
},
innerMode: function (state) {
return {state: state.haskellState, mode: haskellMode};
return state.inCode ? {state: state.baseState, mode: baseMode} : null
}
}
})

CodeMirror.defineMIME("text/x-literate-haskell", "haskell-literate")
})
6 changes: 6 additions & 0 deletions mode/haskell-literate/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ <h2>Haskell literate mode</h2>
</textarea>
</form>

<p><strong>MIME types
defined:</strong> <code>text/x-literate-haskell</code>.</p>

<p>Parser configuration parameters recognized: <code>base</code> to
set the base mode (defaults to <code>"haskell"</code>).</p>

<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {mode: "haskell-literate"});
</script>
Expand Down
2 changes: 1 addition & 1 deletion mode/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ <h2>Language modes</h2>
<li><a href="groovy/index.html">Groovy</a></li>
<li><a href="haml/index.html">HAML</a></li>
<li><a href="handlebars/index.html">Handlebars</a></li>
<li><a href="haskell/index.html">Haskell</a></li>
<li><a href="haskell/index.html">Haskell</a> (<a href="haskell-literate/index.html">Literate</a>)</li>
<li><a href="haxe/index.html">Haxe</a></li>
<li><a href="htmlembedded/index.html">HTML embedded</a> (JSP, ASP.NET)</li>
<li><a href="htmlmixed/index.html">HTML mixed-mode</a></li>
Expand Down
1 change: 1 addition & 0 deletions mode/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
{name: "Groovy", mime: "text/x-groovy", mode: "groovy", ext: ["groovy"]},
{name: "HAML", mime: "text/x-haml", mode: "haml", ext: ["haml"]},
{name: "Haskell", mime: "text/x-haskell", mode: "haskell", ext: ["hs"]},
{name: "Haskell (Literate)", mime: "text/x-literate-haskell", mode: "haskell-literate", ext: ["lhs"]},
{name: "Haxe", mime: "text/x-haxe", mode: "haxe", ext: ["hx"]},
{name: "HXML", mime: "text/x-hxml", mode: "haxe", ext: ["hxml"]},
{name: "ASP.NET", mime: "application/x-aspx", mode: "htmlembedded", ext: ["aspx"], alias: ["asp", "aspx"]},
Expand Down

0 comments on commit 07bcf88

Please sign in to comment.