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
parent c8a6ddc7fd
commit 9aa68303cf
10 changed files with 28 additions and 50 deletions

View File

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

View File

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

View File

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

View File

@ -15,8 +15,14 @@ nsHtml5ViewSourceUtils::NewBodyAttributes()
nsString* id = new nsString(NS_LITERAL_STRING("viewsource"));
bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_ID, id);
nsString* klass = new nsString();
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);
}

View File

@ -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">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>

View File

@ -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>&lt;<span class="start-tag">html</span>&gt;</span>
<span id></span><span>&lt;<span class="start-tag">head</span>&gt;</span>

View File

@ -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>nXX
<span id></span>XX<span class="error">&amp;</span>noXX

View File

@ -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>
</pre>
<!-- View source CSS matches the <pre id> and <span id> elements and produces line numbers. -->

View File

@ -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">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

View File

@ -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>