Bug 1067325 - Control syntax highlighting via a class. r=hsivonen

This commit is contained in:
J. Ryan Stinnett 2015-05-23 18:17:50 -05:00
Родитель a9e07e1d86
Коммит e1f26b0e50
10 изменённых файлов: 28 добавлений и 50 удалений

Просмотреть файл

@ -40,45 +40,45 @@ span[id]:before {
font-weight: normal; font-weight: normal;
font-style: normal; font-style: normal;
} }
.start-tag { .highlight .start-tag {
color: purple; color: purple;
font-weight: bold; font-weight: bold;
} }
.end-tag { .highlight .end-tag {
color: purple; color: purple;
font-weight: bold; font-weight: bold;
} }
.comment { .highlight .comment {
color: green; color: green;
font-style: italic; font-style: italic;
} }
.cdata { .highlight .cdata {
color: #CC0066; color: #CC0066;
} }
.doctype { .highlight .doctype {
color: steelblue; color: steelblue;
font-style: italic; font-style: italic;
} }
.pi { .highlight .pi {
color: orchid; color: orchid;
font-style: italic; font-style: italic;
} }
.entity { .highlight .entity {
color:#FF4500; color: #FF4500;
font-weight: normal; font-weight: normal;
} }
.text { .highlight .text {
font-weight: normal; font-weight: normal;
} }
.attribute-name { .highlight .attribute-name {
color: black; color: black;
font-weight: bold; font-weight: bold;
} }
.attribute-value { .highlight .attribute-value {
color: blue; color: blue;
font-weight: normal; font-weight: normal;
} }
.markupdeclaration { .highlight .markupdeclaration {
color: steelblue; color: steelblue;
font-style: italic; font-style: italic;
} }
@ -88,9 +88,9 @@ span:not(.error), a:not(.error) {
span[id] { span[id] {
unicode-bidi: -moz-isolate; unicode-bidi: -moz-isolate;
} }
.error, .highlight .error,
.error > :-moz-any(.start-tag, .end-tag, .comment, .cdata, .doctype, .pi, .highlight .error > :-moz-any(.start-tag, .end-tag, .comment, .cdata, .doctype,
.entity, .attribute-name, .attribute-value) { .pi, .entity, .attribute-name, .attribute-value) {
color: red; color: red;
font-weight: bold; font-weight: bold;
} }

Просмотреть файл

@ -53,8 +53,6 @@ nsHtml5Highlighter::nsHtml5Highlighter(nsAHtml5TreeOpSink* aOpSink)
, mInlinesOpen(0) , mInlinesOpen(0)
, mInCharacters(false) , mInCharacters(false)
, mBuffer(nullptr) , mBuffer(nullptr)
, mSyntaxHighlight(Preferences::GetBool("view_source.syntax_highlight",
true))
, mOpSink(aOpSink) , mOpSink(aOpSink)
, mCurrentRun(nullptr) , mCurrentRun(nullptr)
, mAmpersand(nullptr) , mAmpersand(nullptr)
@ -713,9 +711,6 @@ nsHtml5Highlighter::AppendCharacters(const char16_t* aBuffer,
void void
nsHtml5Highlighter::AddClass(const char16_t* aClass) nsHtml5Highlighter::AddClass(const char16_t* aClass)
{ {
if (!mSyntaxHighlight) {
return;
}
mOpQueue.AppendElement()->InitAddClass(CurrentNode(), aClass); mOpQueue.AppendElement()->InitAddClass(CurrentNode(), aClass);
} }
@ -751,9 +746,6 @@ nsHtml5Highlighter::AddBase(const nsString& aValue)
void void
nsHtml5Highlighter::AddErrorToCurrentNode(const char* aMsgId) nsHtml5Highlighter::AddErrorToCurrentNode(const char* aMsgId)
{ {
if (!mSyntaxHighlight) {
return;
}
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement(); nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
NS_ASSERTION(treeOp, "Tree op allocation failed."); NS_ASSERTION(treeOp, "Tree op allocation failed.");
treeOp->Init(CurrentNode(), aMsgId); treeOp->Init(CurrentNode(), aMsgId);
@ -762,9 +754,6 @@ nsHtml5Highlighter::AddErrorToCurrentNode(const char* aMsgId)
void void
nsHtml5Highlighter::AddErrorToCurrentRun(const char* aMsgId) nsHtml5Highlighter::AddErrorToCurrentRun(const char* aMsgId)
{ {
if (!mSyntaxHighlight) {
return;
}
NS_PRECONDITION(mCurrentRun, "Adding error to run without one!"); NS_PRECONDITION(mCurrentRun, "Adding error to run without one!");
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement(); nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
NS_ASSERTION(treeOp, "Tree op allocation failed."); NS_ASSERTION(treeOp, "Tree op allocation failed.");
@ -775,9 +764,6 @@ void
nsHtml5Highlighter::AddErrorToCurrentRun(const char* aMsgId, nsHtml5Highlighter::AddErrorToCurrentRun(const char* aMsgId,
nsIAtom* aName) nsIAtom* aName)
{ {
if (!mSyntaxHighlight) {
return;
}
NS_PRECONDITION(mCurrentRun, "Adding error to run without one!"); NS_PRECONDITION(mCurrentRun, "Adding error to run without one!");
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement(); nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
NS_ASSERTION(treeOp, "Tree op allocation failed."); NS_ASSERTION(treeOp, "Tree op allocation failed.");
@ -789,9 +775,6 @@ nsHtml5Highlighter::AddErrorToCurrentRun(const char* aMsgId,
nsIAtom* aName, nsIAtom* aName,
nsIAtom* aOther) nsIAtom* aOther)
{ {
if (!mSyntaxHighlight) {
return;
}
NS_PRECONDITION(mCurrentRun, "Adding error to run without one!"); NS_PRECONDITION(mCurrentRun, "Adding error to run without one!");
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement(); nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
NS_ASSERTION(treeOp, "Tree op allocation failed."); NS_ASSERTION(treeOp, "Tree op allocation failed.");
@ -801,9 +784,6 @@ nsHtml5Highlighter::AddErrorToCurrentRun(const char* aMsgId,
void void
nsHtml5Highlighter::AddErrorToCurrentAmpersand(const char* aMsgId) nsHtml5Highlighter::AddErrorToCurrentAmpersand(const char* aMsgId)
{ {
if (!mSyntaxHighlight) {
return;
}
NS_PRECONDITION(mAmpersand, "Adding error to ampersand without one!"); NS_PRECONDITION(mAmpersand, "Adding error to ampersand without one!");
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement(); nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
NS_ASSERTION(treeOp, "Tree op allocation failed."); NS_ASSERTION(treeOp, "Tree op allocation failed.");
@ -813,9 +793,6 @@ nsHtml5Highlighter::AddErrorToCurrentAmpersand(const char* aMsgId)
void void
nsHtml5Highlighter::AddErrorToCurrentSlash(const char* aMsgId) nsHtml5Highlighter::AddErrorToCurrentSlash(const char* aMsgId)
{ {
if (!mSyntaxHighlight) {
return;
}
NS_PRECONDITION(mSlash, "Adding error to slash without one!"); NS_PRECONDITION(mSlash, "Adding error to slash without one!");
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement(); nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
NS_ASSERTION(treeOp, "Tree op allocation failed."); NS_ASSERTION(treeOp, "Tree op allocation failed.");

Просмотреть файл

@ -313,11 +313,6 @@ class nsHtml5Highlighter
*/ */
nsHtml5UTF16Buffer* mBuffer; nsHtml5UTF16Buffer* mBuffer;
/**
* Whether to highlight syntax visibly initially.
*/
bool mSyntaxHighlight;
/** /**
* The outgoing tree op queue. * The outgoing tree op queue.
*/ */

Просмотреть файл

@ -15,8 +15,14 @@ nsHtml5ViewSourceUtils::NewBodyAttributes()
nsString* id = new nsString(NS_LITERAL_STRING("viewsource")); nsString* id = new nsString(NS_LITERAL_STRING("viewsource"));
bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_ID, id); bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_ID, id);
nsString* klass = new nsString();
if (mozilla::Preferences::GetBool("view_source.wrap_long_lines", true)) { if (mozilla::Preferences::GetBool("view_source.wrap_long_lines", true)) {
nsString* klass = new nsString(NS_LITERAL_STRING("wrap")); klass->Append(NS_LITERAL_STRING("wrap "));
}
if (mozilla::Preferences::GetBool("view_source.syntax_highlight", true)) {
klass->Append(NS_LITERAL_STRING("highlight"));
}
if (!klass->IsEmpty()) {
bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_CLASS, klass); bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_CLASS, klass);
} }

Просмотреть файл

@ -1,4 +1,4 @@
<!DOCTYPE html><html><head><title></title><link rel="stylesheet" type="text/css" href="resource://gre-resources/viewsource.css"></head><body id="viewsource" class="wrap"><pre id><span class="doctype">&lt;!DOCTYPE html&gt;</span> <!DOCTYPE html><html><head><title></title><link rel="stylesheet" type="text/css" href="resource://gre-resources/viewsource.css"></head><body id="viewsource" class="wrap highlight"><pre id><span class="doctype">&lt;!DOCTYPE html&gt;</span>
<span id></span><span>&lt;<span class="start-tag">html</span>&gt;</span> <span id></span><span>&lt;<span class="start-tag">html</span>&gt;</span>
<span id></span><span>&lt;<span class="start-tag">head</span>&gt;</span> <span id></span><span>&lt;<span class="start-tag">head</span>&gt;</span>
<span id></span><span>&lt;<span class="start-tag">title</span>&gt;</span><span>Title</span><span>&lt;/<span class="end-tag">title</span>&gt;</span> <span id></span><span>&lt;<span class="start-tag">title</span>&gt;</span><span>Title</span><span>&lt;/<span class="end-tag">title</span>&gt;</span>

Просмотреть файл

@ -1,4 +1,4 @@
<!DOCTYPE html><html><head><title></title><link rel="stylesheet" type="text/css" href="resource://gre-resources/viewsource.css"></head><body id="viewsource" class="wrap"><pre id><span class="pi">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span> <!DOCTYPE html><html><head><title></title><link rel="stylesheet" type="text/css" href="resource://gre-resources/viewsource.css"></head><body id="viewsource" class="wrap highlight"><pre id><span class="pi">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span>
<span id></span><span class="pi">&lt;?foo bar?&gt;</span> <span id></span><span class="pi">&lt;?foo bar?&gt;</span>
<span id></span><span>&lt;<span class="start-tag">html</span>&gt;</span> <span id></span><span>&lt;<span class="start-tag">html</span>&gt;</span>
<span id></span><span>&lt;<span class="start-tag">head</span>&gt;</span> <span id></span><span>&lt;<span class="start-tag">head</span>&gt;</span>

Просмотреть файл

@ -1,4 +1,4 @@
<!DOCTYPE html><html><head><title></title><link rel="stylesheet" type="text/css" href="resource://gre-resources/viewsource.css"></head><body id="viewsource" class="wrap"><pre id><span class="doctype">&lt;!DOCTYPE html&gt;</span> <!DOCTYPE html><html><head><title></title><link rel="stylesheet" type="text/css" href="resource://gre-resources/viewsource.css"></head><body id="viewsource" class="wrap highlight"><pre id><span class="doctype">&lt;!DOCTYPE html&gt;</span>
<span id></span>XX<span class="error">&amp;</span>XX <span id></span>XX<span class="error">&amp;</span>XX
<span id></span>XX<span class="error">&amp;</span>nXX <span id></span>XX<span class="error">&amp;</span>nXX
<span id></span>XX<span class="error">&amp;</span>noXX <span id></span>XX<span class="error">&amp;</span>noXX

Просмотреть файл

@ -1,4 +1,4 @@
<!DOCTYPE html><html><head><title></title><link rel="stylesheet" type="text/css" href="resource://gre-resources/viewsource.css"></head><body id="viewsource" class="wrap"><pre id><span class="error comment">&lt;!--&gt;</span> <span class="error comment">&lt;!X&gt;</span> <!DOCTYPE html><html><head><title></title><link rel="stylesheet" type="text/css" href="resource://gre-resources/viewsource.css"></head><body id="viewsource" class="wrap highlight"><pre id><span class="error comment">&lt;!--&gt;</span> <span class="error comment">&lt;!X&gt;</span>
<span id></span> <span id></span>
</pre> </pre>
<!-- View source CSS matches the <pre id> and <span id> elements and produces line numbers. --> <!-- View source CSS matches the <pre id> and <span id> elements and produces line numbers. -->

Просмотреть файл

@ -1,4 +1,4 @@
<!DOCTYPE html><html><head><title></title><link rel="stylesheet" type="text/css" href="resource://gre-resources/viewsource.css"></head><body id="viewsource" class="wrap"><pre id><span class="doctype">&lt;!DOCTYPE html&gt;</span><span> <!DOCTYPE html><html><head><title></title><link rel="stylesheet" type="text/css" href="resource://gre-resources/viewsource.css"></head><body id="viewsource" class="wrap highlight"><pre id><span class="doctype">&lt;!DOCTYPE html&gt;</span><span>
<span id></span></span><span>&lt;<span class="start-tag">body</span>&gt;</span><span> <span id></span></span><span>&lt;<span class="start-tag">body</span>&gt;</span><span>
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;/<span class="end-tag">script</span>&gt;</span><span>X <span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;/<span class="end-tag">script</span>&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;/<span class="end-tag">script</span> &gt;</span><span>X <span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;/<span class="end-tag">script</span> &gt;</span><span>X

Просмотреть файл

@ -1,2 +1,2 @@
<!DOCTYPE html><html><head><title></title><link rel="stylesheet" type="text/css" href="resource://gre-resources/viewsource.css"></head><body id="viewsource" style="-moz-tab-size: 4"><pre id="line1"><span></span><span class="doctype">&lt;!DOCTYPE html&gt;</span><span></span><span>&lt;<span class="start-tag">table</span>&gt;</span><span></span><span title="Start tag “input” seen in “table”." class="error">&lt;<span class="start-tag">input</span> <span class="attribute-name">type</span>=<a class="attribute-value">hidden</a>&gt;</span><span></span><span>&lt;/<span class="end-tag">table</span>&gt;</span><span> <!DOCTYPE html><html><head><title></title><link rel="stylesheet" type="text/css" href="resource://gre-resources/viewsource.css"></head><body id="viewsource" class="highlight" style="-moz-tab-size: 4"><pre id="line1"><span></span><span class="doctype">&lt;!DOCTYPE html&gt;</span><span></span><span>&lt;<span class="start-tag">table</span>&gt;</span><span></span><span title="Start tag “input” seen in “table”." class="error">&lt;<span class="start-tag">input</span> <span class="attribute-name">type</span>=<a class="attribute-value">hidden</a>&gt;</span><span></span><span>&lt;/<span class="end-tag">table</span>&gt;</span><span>
<span id="line2"></span></span></pre></body></html> <span id="line2"></span></span></pre></body></html>