Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CodeMirror
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Moritz Aurel Pascal Schubotz
CodeMirror
Commits
7d36a0f7
Commit
7d36a0f7
authored
13 years ago
by
Dror BG
Committed by
Marijn Haverbeke
13 years ago
Browse files
Options
Downloads
Patches
Plain Diff
added support for XML processing instructions
parent
dfd44fbd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
Loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mode/xmlpure/xmlpure.js
+68
-22
68 additions, 22 deletions
mode/xmlpure/xmlpure.js
with
68 additions
and
22 deletions
mode/xmlpure/xmlpure.js
+
68
−
22
View file @
7d36a0f7
...
...
@@ -9,14 +9,14 @@
CodeMirror
.
defineMode
(
"
xmlpure
"
,
function
(
config
,
parserConfig
)
{
// constants
var
STYLE_ERROR
=
"
error
"
;
var
STYLE_
DECLARA
TION
=
"
comment
"
;
var
STYLE_
INSTRUC
TION
=
"
comment
"
;
var
STYLE_COMMENT
=
"
comment
"
;
var
STYLE_ELEMENT_NAME
=
"
tag
"
;
var
STYLE_ATTRIBUTE
=
"
attribute
"
;
var
STYLE_WORD
=
"
string
"
;
var
STYLE_TEXT
=
"
atom
"
;
var
TAG_
DECLARA
TION
=
"
!
declara
tion
"
;
var
TAG_
INSTRUC
TION
=
"
!
instruc
tion
"
;
var
TAG_CDATA
=
"
!cdata
"
;
var
TAG_COMMENT
=
"
!comment
"
;
var
TAG_TEXT
=
"
!text
"
;
...
...
@@ -25,7 +25,7 @@ CodeMirror.defineMode("xmlpure", function(config, parserConfig) {
"
!cdata
"
:
true
,
"
!comment
"
:
true
,
"
!text
"
:
true
,
"
!
declara
tion
"
:
true
"
!
instruc
tion
"
:
true
};
// options
...
...
@@ -85,7 +85,7 @@ CodeMirror.defineMode("xmlpure", function(config, parserConfig) {
// return true if the current token is seperated from the tokens before it
// which means either this is the start of the line, or there is at least
// one space or tab character behind the token
// other returns false
// other
wise
returns false
function
isTokenSeparated
(
stream
)
{
return
stream
.
sol
()
||
stream
.
string
.
charAt
(
stream
.
start
-
1
)
==
"
"
||
...
...
@@ -102,16 +102,11 @@ CodeMirror.defineMode("xmlpure", function(config, parserConfig) {
// - zero or more comments
function
parseDocument
(
stream
,
state
)
{
if
(
stream
.
eat
(
"
<
"
))
{
if
(
stream
.
match
(
"
?xml
"
))
{
// declaration
if
(
state
.
lineNumber
>
1
||
stream
.
pos
>
5
)
{
stream
.
skipToEnd
();
return
STYLE_ERROR
;
}
else
{
pushContext
(
state
,
TAG_DECLARATION
);
state
.
tokenize
=
parseDeclarationVersion
;
return
STYLE_DECLARATION
;
}
if
(
stream
.
eat
(
"
?
"
))
{
// processing instruction
pushContext
(
state
,
TAG_INSTRUCTION
);
state
.
tokenize
=
parseProcessingInstructionStartTag
;
return
STYLE_INSTRUCTION
;
}
else
if
(
stream
.
match
(
"
!--
"
))
{
// new context: comment
pushContext
(
state
,
TAG_COMMENT
);
...
...
@@ -273,7 +268,11 @@ CodeMirror.defineMode("xmlpure", function(config, parserConfig) {
// - comments
function
parseElementBlock
(
stream
,
state
)
{
if
(
stream
.
eat
(
"
<
"
))
{
if
(
stream
.
match
(
"
!--
"
))
{
if
(
stream
.
match
(
"
?
"
))
{
pushContext
(
state
,
TAG_INSTRUCTION
);
state
.
tokenize
=
parseProcessingInstructionStartTag
;
return
STYLE_INSTRUCTION
;
}
else
if
(
stream
.
match
(
"
!--
"
))
{
// new context: comment
pushContext
(
state
,
TAG_COMMENT
);
return
chain
(
stream
,
state
,
inBlock
(
STYLE_COMMENT
,
"
-->
"
,
...
...
@@ -313,6 +312,52 @@ CodeMirror.defineMode("xmlpure", function(config, parserConfig) {
}
return
STYLE_TEXT
;
}
///////////////////////////////////////////////////////////////////////////
// context: XML processing instructions
//
// XML processing instructions (PIs) allow documents to contain instructions for applications.
// PI format: <?name data?>
// - 'name' can be anything other than 'xml' (case-insensitive)
// - 'data' can be anything which doesn't contain '?>'
// XML declaration is a special PI (see XML declaration context below)
function
parseProcessingInstructionStartTag
(
stream
,
state
)
{
if
(
stream
.
match
(
"
xml
"
,
true
,
true
))
{
// xml declaration
if
(
state
.
lineNumber
>
1
||
stream
.
pos
>
5
)
{
state
.
tokenize
=
parseDocument
;
stream
.
skipToEnd
();
return
STYLE_ERROR
;
}
else
{
state
.
tokenize
=
parseDeclarationVersion
;
return
STYLE_INSTRUCTION
;
}
}
// regular processing instruction
if
(
isTokenSeparated
(
stream
)
||
stream
.
match
(
"
?>
"
))
{
// we have a space after the start-tag, or nothing but the end-tag
// either way - error!
state
.
tokenize
=
parseDocument
;
stream
.
skipToEnd
();
return
STYLE_ERROR
;
}
state
.
tokenize
=
parseProcessingInstructionBody
;
return
STYLE_INSTRUCTION
;
}
function
parseProcessingInstructionBody
(
stream
,
state
)
{
stream
.
eatWhile
(
/
[^
?
]
/
);
if
(
stream
.
eat
(
"
?
"
))
{
if
(
stream
.
eat
(
"
>
"
))
{
popContext
(
state
);
state
.
tokenize
=
state
.
context
==
null
?
parseDocument
:
parseElementBlock
;
}
}
return
STYLE_INSTRUCTION
;
}
///////////////////////////////////////////////////////////////////////////
// context: XML declaration
...
...
@@ -325,11 +370,11 @@ CodeMirror.defineMode("xmlpure", function(config, parserConfig) {
// - may include 'encoding' and 'standalone' (in that order after 'version')
// - attribute names must be lowercase
// - cannot contain anything else on the line
function
parseDeclarationVersion
(
stream
,
state
)
{
state
.
tokenize
=
parseDeclarationEncoding
;
state
.
tokenize
=
parseDeclarationEncoding
;
if
(
isTokenSeparated
(
stream
)
&&
stream
.
match
(
/^version
(
)
*=
(
)
*"
([
a-zA-Z0-9_.:
]
|
\-)
+"/
))
{
return
STYLE_
DECLARA
TION
;
return
STYLE_
INSTRUC
TION
;
}
stream
.
skipToEnd
();
return
STYLE_ERROR
;
...
...
@@ -339,7 +384,7 @@ CodeMirror.defineMode("xmlpure", function(config, parserConfig) {
state
.
tokenize
=
parseDeclarationStandalone
;
if
(
isTokenSeparated
(
stream
)
&&
stream
.
match
(
/^encoding
(
)
*=
(
)
*"
[
A-Za-z
]([
A-Za-z0-9._
]
|
\-)
*"/
))
{
return
STYLE_
DECLARA
TION
;
return
STYLE_
INSTRUC
TION
;
}
return
null
;
}
...
...
@@ -348,16 +393,17 @@ CodeMirror.defineMode("xmlpure", function(config, parserConfig) {
state
.
tokenize
=
parseDeclarationEndTag
;
if
(
isTokenSeparated
(
stream
)
&&
stream
.
match
(
/^standalone
(
)
*=
(
)
*"
(
yes|no
)
"/
))
{
return
STYLE_
DECLARA
TION
;
return
STYLE_
INSTRUC
TION
;
}
return
null
;
}
function
parseDeclarationEndTag
(
stream
,
state
)
{
state
.
tokenize
=
parseDocument
;
if
(
stream
.
match
(
"
?>
"
)
&&
stream
.
eol
())
{
popContext
(
state
);
return
STYLE_
DECLARA
TION
;
return
STYLE_
INSTRUC
TION
;
}
stream
.
skipToEnd
();
return
STYLE_ERROR
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment