Handle dead cross-board quotelinks. Handle multiple dead quotelinks per text nodes.
This commit is contained in:
parent
e3fe3f6606
commit
6a9320dd81
@ -3341,22 +3341,35 @@
|
|||||||
return g.callbacks.push(this.node);
|
return g.callbacks.push(this.node);
|
||||||
},
|
},
|
||||||
node: function(post) {
|
node: function(post) {
|
||||||
var data, i, index, node, nodes, quote, snapshot, text, _ref;
|
var board, className, data, href, i, id, index, m, node, nodes, quote, quotes, snapshot, text, _i, _len, _ref;
|
||||||
if (post["class"] === 'inline') return;
|
if (post["class"] === 'inline') return;
|
||||||
snapshot = d.evaluate('.//*[not(self::a) and contains(text(),">>")]/text()', post.el.lastChild, null, 7, null);
|
snapshot = d.evaluate('.//text()[not(ancestor::a)]', post.el.lastChild, null, 6, null);
|
||||||
for (i = 0, _ref = snapshot.snapshotLength; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) {
|
for (i = 0, _ref = snapshot.snapshotLength; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) {
|
||||||
node = snapshot.snapshotItem(i);
|
node = snapshot.snapshotItem(i);
|
||||||
data = node.data;
|
data = node.data;
|
||||||
if (!(quote = data.match(/>>(\d+)/))) continue;
|
if (!(quotes = data.match(/>>(\d+|>\/[a-z\d]+\/\d+)/g))) continue;
|
||||||
index = data.indexOf(quote[0]);
|
|
||||||
nodes = [];
|
nodes = [];
|
||||||
if (text = data.slice(0, index)) nodes.push($.tn(text));
|
for (_i = 0, _len = quotes.length; _i < _len; _i++) {
|
||||||
nodes.push($.el('a', {
|
quote = quotes[_i];
|
||||||
textContent: "" + quote[0] + "\u00A0(Dead)",
|
index = data.indexOf(quote);
|
||||||
href: "#" + quote[1],
|
if (text = data.slice(0, index)) nodes.push($.tn(text));
|
||||||
className: $.id(quote[1]) ? 'quotelink' : null
|
id = quote.match(/\d+$/)[0];
|
||||||
}));
|
board = (m = quote.match(/^>>>\/([a-z\d]+)/)) ? m[1] : g.BOARD;
|
||||||
if (text = data.slice(index + quote[0].length)) nodes.push($.tn(text));
|
if (board === g.BOARD && $.id(id)) {
|
||||||
|
href = "#" + id;
|
||||||
|
className = 'quotelink';
|
||||||
|
} else {
|
||||||
|
href = "#";
|
||||||
|
className = null;
|
||||||
|
}
|
||||||
|
nodes.push($.el('a', {
|
||||||
|
textContent: "" + quote + "\u00A0(Dead)",
|
||||||
|
href: href,
|
||||||
|
className: className
|
||||||
|
}));
|
||||||
|
data = data.slice(index + quote.length);
|
||||||
|
}
|
||||||
|
if (data) nodes.push($.tn(data));
|
||||||
$.replace(node, nodes);
|
$.replace(node, nodes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -584,7 +584,7 @@ Filter =
|
|||||||
sub.textContent
|
sub.textContent
|
||||||
comment: (post) ->
|
comment: (post) ->
|
||||||
text = []
|
text = []
|
||||||
# XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE is 7
|
# XPathResult.ORDERED_NODE_SNAPSHOT_TYPE is 7
|
||||||
nodes = d.evaluate './/br|.//text()', post.el.lastChild, null, 7, null
|
nodes = d.evaluate './/br|.//text()', post.el.lastChild, null, 7, null
|
||||||
for i in [0...nodes.snapshotLength]
|
for i in [0...nodes.snapshotLength]
|
||||||
text.push if data = nodes.snapshotItem(i).data then data else '\n'
|
text.push if data = nodes.snapshotItem(i).data then data else '\n'
|
||||||
@ -2772,28 +2772,50 @@ DeadQuotes =
|
|||||||
g.callbacks.push @node
|
g.callbacks.push @node
|
||||||
node: (post) ->
|
node: (post) ->
|
||||||
return if post.class is 'inline'
|
return if post.class is 'inline'
|
||||||
# XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE is 7
|
|
||||||
|
|
||||||
# We need to make sure we can quotify multiple links per text node
|
# XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE is 6
|
||||||
# We need to make sure that we don't try to quotify text like `>>text`
|
# Get all the text nodes that are not inside an anchor.
|
||||||
|
snapshot = d.evaluate './/text()[not(ancestor::a)]', post.el.lastChild, null, 6, null
|
||||||
|
|
||||||
snapshot = d.evaluate './/*[not(self::a) and contains(text(),">>")]/text()', post.el.lastChild, null, 7, null
|
|
||||||
for i in [0...snapshot.snapshotLength]
|
for i in [0...snapshot.snapshotLength]
|
||||||
node = snapshot.snapshotItem i
|
node = snapshot.snapshotItem i
|
||||||
data = node.data
|
data = node.data
|
||||||
unless quote = data.match />>(\d+)/
|
|
||||||
|
unless quotes = data.match />>(\d+|>\/[a-z\d]+\/\d+)/g
|
||||||
|
# Only accept nodes with potentially valid links
|
||||||
continue
|
continue
|
||||||
index = data.indexOf quote[0]
|
|
||||||
nodes = []
|
nodes = []
|
||||||
if text = data[0...index]
|
|
||||||
nodes.push $.tn text
|
for quote in quotes
|
||||||
nodes.push $.el 'a',
|
index = data.indexOf quote
|
||||||
# \u00A0 is nbsp
|
if text = data[...index]
|
||||||
textContent: "#{quote[0]}\u00A0(Dead)"
|
# Potential text before this valid quote.
|
||||||
href: "##{quote[1]}" # Here be archive link
|
nodes.push $.tn text
|
||||||
className: if $.id quote[1] then 'quotelink' else null
|
|
||||||
if text = data[index + quote[0].length...]
|
id = quote.match(/\d+$/)[0]
|
||||||
nodes.push $.tn text
|
board = if m = quote.match /^>>>\/([a-z\d]+)/ then m[1] else g.BOARD
|
||||||
|
if board is g.BOARD and $.id id
|
||||||
|
href = "##{id}"
|
||||||
|
className = 'quotelink'
|
||||||
|
else
|
||||||
|
# TODO manage links if board is archived
|
||||||
|
# Here be archive link
|
||||||
|
href = "#"
|
||||||
|
className = null
|
||||||
|
|
||||||
|
nodes.push $.el 'a',
|
||||||
|
# \u00A0 is nbsp
|
||||||
|
textContent: "#{quote}\u00A0(Dead)"
|
||||||
|
href: href
|
||||||
|
className: className
|
||||||
|
|
||||||
|
data = data[index + quote.length..]
|
||||||
|
|
||||||
|
if data
|
||||||
|
# Potential text after the last valid quote.
|
||||||
|
nodes.push $.tn data
|
||||||
|
|
||||||
$.replace node, nodes
|
$.replace node, nodes
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user