Skip to content

Commit

Permalink
#12 Treat {color} as formatting syntax instead of block
Browse files Browse the repository at this point in the history
  • Loading branch information
melloc committed Jul 16, 2019
1 parent bae9bf1 commit eadc96e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
18 changes: 9 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var mod_parser = require('./alt-parser');
var escapeHTML = mod_ent.encode;

/* BEGIN JSSTYLED */
var COLOR_RE = /^([a-z]+|#[a-f]{6})$/i;
var COLOR_RE = /^([a-z]+|#[a-f0-9]{6})$/i;
var EMBED_OPTS_RE = /,\s*/;
/* END JSSTYLED */

Expand Down Expand Up @@ -147,14 +147,6 @@ var ToHTML = {

return createPanelBlock(['code', 'panel'], opts, inner);
},
block_color: function (contents) {
var opts = nodeToOptions(contents);
var open = '<div';
if (opts.length > 0 && COLOR_RE.test(opts[0])) {
open += ' style="color: ' + opts[0] + '"';
}
return open + '>\n' + contents.visit(ToHTML) + '\n</div>';
},
block_quote: function (contents) {
var inner = contents.visit(ToHTML);
return '<blockquote>\n' + inner + '\n</blockquote>';
Expand Down Expand Up @@ -290,6 +282,14 @@ var ToHTML = {
markupWord_user: function (_lb, user, _rb) {
return '@' + escapeHTML(user.sourceString);
},
markupWord_color: function (_lb, options, _rb, contents, _close) {
var opts = optionStrToArr(options.child(0).visit(ToHTML));
var open = '<span';
if (opts.length > 0 && COLOR_RE.test(opts[0])) {
open += ' style="color: ' + opts[0] + '"';
}
return open + '>' + contents.visit(ToHTML) + '</span>';
},
markupWord_formatted: function (sp, fmt) {
return sp.visit(ToHTML) + nodesToHTML(fmt, '');
},
Expand Down
4 changes: 2 additions & 2 deletions lib/jira.ohm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ JIRA {
| readUntil<"code"> -- code
| namedBlock<"panel"> -- panel
| namedBlock<"quote"> -- quote
| namedBlock<"color"> -- color
| bq space* words<no> -- blockquote
| (bullet (space* ~bullet iblock<no> (nl? | &no))+)+ -- list
| ~no row+ -- table
Expand Down Expand Up @@ -100,6 +99,7 @@ JIRA {
| "[" markupWordUntil<"|", excl>? "^" space* urichars space* "]" -- attachment
| "[~" (~"]" ident)+ "]" -- user
| "!" (~"!" filechar)+ ("|" (~"!" ident)+)? "!" -- embed
| "{color" options? "}" markupWordUntil<"{color}", excl> -- color
| "{{" markupWordUntil<"}}", excl> -- monospace
| (space | ~formchar ~char punct) ~excl formatted<excl>+ -- formatted
| bareurl
Expand Down Expand Up @@ -137,7 +137,7 @@ JIRA {
nl (a newline) = "\r\n" | "\n" | "\r"
blankl = space* nl

blockStart = "{" ("quote" | "panel" | "color" | "noformat" | "code")
blockStart = "{" ("quote" | "panel" | "noformat" | "code")

formchar (a format character) = "*" | "_" | "~" | "-" | "+" | "^" | "??"
punct = "\u0021".."\u002f" | "\u003a".."\u0040" | "\u005b".."\u0060" | "\u007b".."\u007E"
Expand Down
13 changes: 10 additions & 3 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,18 @@ test('{panel} blocks', function (t) {

test('{color} blocks', function (t) {
t.equal(toHTML('{color:red}hello{color}'),
'<div style="color: red">\n<p>hello</p>\n</div>');
'<p><span style="color: red">hello</span></p>');
t.equal(toHTML('{color:blue}hello{color}'),
'<div style="color: blue">\n<p>hello</p>\n</div>');
'<p><span style="color: blue">hello</span></p>');
t.equal(toHTML('{color:#ffffff}hello{color}'),
'<div style="color: #ffffff">\n<p>hello</p>\n</div>');
'<p><span style="color: #ffffff">hello</span></p>');

// In the middle of a sentence
t.equal(toHTML('This is a {color:red}red{color} word'),
'<p>This is a <span style="color: red">red</span> word</p>');
t.equal(toHTML('Using {color:#3d3c40}hex{color}.'),
'<p>Using <span style="color: #3d3c40">hex</span>.</p>');

t.end();
});

Expand Down

0 comments on commit eadc96e

Please sign in to comment.