From f450a28d11b61d414bf065f8b4cbd51236104a85 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 12 Jul 2017 11:09:53 +0200 Subject: [PATCH] improve logic for guessing titles within code documents --- www/common/common-codemirror.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/www/common/common-codemirror.js b/www/common/common-codemirror.js index 333059a1d..618e51dd7 100644 --- a/www/common/common-codemirror.js +++ b/www/common/common-codemirror.js @@ -100,8 +100,18 @@ define([ var text = ''; lines.some(function (line) { + // lines including a c-style comment are also valuable + var clike = /^\s*(\/\*|\/\/)(.*)?(\*\/)*$/; + if (clike.test(line)) { + line.replace(clike, function (a, one, two) { + if (!(two && two.replace)) { return; } + text = two.replace(/\*\/\s*$/, '').trim(); + }); + return true; + } + // lisps? - var lispy = /^\s*(;|#\|)(.*?)$/; + var lispy = /^\s*(;|#\|)+(.*?)$/; if (lispy.test(line)) { line.replace(lispy, function (a, one, two) { text = two; @@ -111,7 +121,7 @@ define([ // lines beginning with a hash are potentially valuable // works for markdown, python, bash, etc. - var hash = /^#(.*?)$/; + var hash = /^#+(.*?)$/; if (hash.test(line)) { line.replace(hash, function (a, one) { text = one; @@ -119,16 +129,6 @@ define([ return true; } - // lines including a c-style comment are also valuable - var clike = /^\s*(\/\*|\/\/)(.*)?(\*\/)*$/; - if (clike.test(line)) { - line.replace(clike, function (a, one, two) { - if (!(two && two.replace)) { return; } - text = two.replace(/\*\/\s*$/, '').trim(); - }); - return true; - } - // TODO make one more pass for multiline comments });