-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nikos M
committed
Apr 9, 2016
1 parent
36b919e
commit 3f47701
Showing
2 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
|
||
<meta charset="utf-8"> | ||
|
||
<link rel="stylesheet" href="codemirror/codemirror.css"> | ||
<link rel="stylesheet" href="codemirror/addon/lint/lint.css"> | ||
<link rel="stylesheet" href="codemirror/addon/hint/show-hint.css"> | ||
<link rel="stylesheet" href="codemirror/addon/fold/foldgutter.css" /> | ||
<style type="text/css"> | ||
body { | ||
position: relative; | ||
} | ||
|
||
.CodeMirror { | ||
margin: 0; | ||
position: relative; | ||
width: 100%; | ||
height: 100%; | ||
min-width:500px; | ||
min-height:500px; | ||
} | ||
</style> | ||
|
||
<script src="codemirror/codemirror.js"></script> | ||
<script src="codemirror/addon/comment/comment.js"></script> | ||
<script src="codemirror/addon/lint/lint.js"></script> | ||
<script src="codemirror/addon/hint/show-hint.js"></script> | ||
<script src="codemirror/addon/fold/foldcode.js"></script> | ||
<script src="codemirror/addon/fold/foldgutter.js"></script> | ||
<!--<script src="codemirror/addon/fold/xml-fold.js"></script> | ||
<script src="codemirror/addon/fold/comment-fold.js"></script>--> | ||
<script src="../build/codemirror_grammar.js"></script> | ||
<!-- these grammars are used only for demo, better grammars can be used --> | ||
<script src="grammars/javascript.js"></script> | ||
<script src="grammars/css.js"></script> | ||
<script src="grammars/htmlmixed.js"></script> | ||
<script src="demo.js"></script> | ||
|
||
<title>CodeMirror: Dynamic Mixed HTML + JavaScript + CSS Grammar Demo</title> | ||
</head> | ||
<body> | ||
|
||
<h3>CodeMirror (v.<span id="editor-version">0</span>) Grammar (v.<span id="grammar-version">0</span>): Dynamic Mixed HTML + JavaScript + CSS Grammar</h3> | ||
<textarea id="code" name="code"><?xml version="1.0" encoding="utf-8"?> | ||
<!doctype html> | ||
<html id="id1" id="id2" style = "color: green"> | ||
<!-- this is a comment --> | ||
<head id="id1"> | ||
<title>HTML Example</title> | ||
<style> | ||
/* Some example CSS */ | ||
@import url("something.css"); | ||
body { | ||
margin: 0; | ||
padding: 3em 6em; | ||
font-family: tahoma, arial, sans-serif; | ||
color: #000; | ||
} | ||
h1:before, h2:before { | ||
content: "::"; | ||
} | ||
</style> | ||
<script> | ||
/* a comment */ | ||
var bar = { foo: [1, 2, 3, {"foo3":"foo4"}], | ||
/* a long | ||
comment */ | ||
foo2: 123 | ||
}; | ||
</script> | ||
</head> | ||
<body id="id1"> | ||
<!-- this is a | ||
long comment --> | ||
<div class="divclass"> | ||
<![CDATA[ | ||
cdata text in here | ||
<a_tag>, etc.. | ||
]]> | ||
</div> | ||
The indentation tries to be <em>somewhat &quot;do what | ||
I mean&quot;</em>... but might not match your style. | ||
</bdy> | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!doctype html> | ||
</html> | ||
</textarea> | ||
<p></p> | ||
|
||
<script> | ||
// <![CDATA[ | ||
codemirror_grammar_demo(document.getElementById("code"), [ | ||
{language : "htmlmixed", grammar : htmlmixed_grammar} | ||
,{language : "javascript", grammar : js_grammar} | ||
,{language : "css", grammar : css_grammar} | ||
]); | ||
// ]]> | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// 1. a partial html grammar with mixed javascript/css sub-grammars in simple JSON format | ||
var htmlmixed_grammar = { | ||
|
||
// prefix ID for regular expressions, represented as strings, used in the grammar | ||
"RegExpID" : "RE::", | ||
|
||
"Extra" : { | ||
|
||
"fold" : "xml" | ||
//"electricChars" : "<" | ||
|
||
}, | ||
|
||
// Style model | ||
"Style" : { | ||
|
||
"comment" : "comment" | ||
,"declaration" : "tag" | ||
,"doctype" : "meta" | ||
,"meta" : "meta" | ||
,"cdata" : "atom" | ||
,"tag" : "tag" | ||
,"attribute" : "attribute" | ||
,"string" : "string" | ||
,"atom" : "atom" | ||
,"number" : "number" | ||
,"error" : "error" | ||
|
||
}, | ||
|
||
// Lexical model | ||
"Lex" : { | ||
|
||
"comment:comment" : ["<!--", "-->"] | ||
,"declaration:block" : ["<?xml", "?>"] | ||
,"doctype:block" : ["RE::/<!doctype\\b/i", ">"] | ||
,"meta:block" : ["RE::/<\\?[_a-zA-Z][\\w\\._\\-]*/", "?>"] | ||
,"cdata:block" : ["<![CDATA[", "]]>"] | ||
,"open_tag" : "RE::/<([_a-zA-Z][_a-zA-Z0-9\\-]*)/" | ||
,"close_tag" : "RE::/<\\/([_a-zA-Z][_a-zA-Z0-9\\-]*)>/" | ||
,"attribute" : "RE::/[_a-zA-Z][_a-zA-Z0-9\\-]*/" | ||
,"string:line-block" : [["\""], ["'"]] | ||
,"number" : ["RE::/[0-9]\\d*/", "RE::/#[0-9a-fA-F]+/"] | ||
,"atom" : ["RE::/&#x[a-fA-F\\d]+;/", "RE::/&#[\\d]+;/", "RE::/&[a-zA-Z][a-zA-Z0-9]*;/"] | ||
,"text" : "RE::/[^<&]+/" | ||
|
||
// actions | ||
,"tag_ctx:action" : {"context":true} | ||
,"\\tag_ctx:action" : {"context":false} | ||
,"unique_id:action" : {"unique":["xml", "$1"],"msg":"Duplicate id value \"$0\""} | ||
,"unique_att:action" : {"unique":["tag", "$0"],"msg":"Duplicate attribute \"$0\"","in-context":true} | ||
,"tag_opened:action" : {"push":"<$1>","ci":true} | ||
,"tag_closed:action" : {"pop":"<$1>","ci":true,"msg":"Tags \"$0\" and \"$1\" do not match"} | ||
,"tag_autoclosed:action" : {"pop":null} | ||
,"out_of_place:error" : "\"$2$3\" can only be at the beginning of XML document" | ||
|
||
}, | ||
|
||
// Syntax model (optional) | ||
"Syntax" : { | ||
|
||
"javascript" : {"subgrammar":"javascript"} | ||
,"css" : {"subgrammar":"css"} | ||
,"tag_att" : "'id'.attribute unique_att '=' string unique_id | attribute unique_att '=' (string | number)" | ||
,"style_tag" : "'<style>'.tag css '</style>'.tag" | ||
,"script_tag" : "'<script>'.tag javascript '</script>'.tag" | ||
,"start_tag" : "open_tag.tag tag_ctx tag_opened tag_att* ('>'.tag | '/>'.tag tag_autoclosed) \\tag_ctx" | ||
,"end_tag" : "close_tag.tag tag_closed" | ||
,"htmlmixed" : "(^^1 declaration? doctype?) (declaration.error out_of_place | doctype.error out_of_place | comment | meta | cdata | style_tag | script_tag | start_tag | end_tag | atom | text)*" | ||
|
||
}, | ||
|
||
// what to parse and in what order | ||
"Parser" : [ ["htmlmixed"] ] | ||
|
||
}; |