Просмотр исходного кода

BugFix and refactor appendEditSectionButtons

Yuki Takei 8 лет назад
Родитель
Сommit
56d8d2f9c9
4 измененных файлов с 2 добавлено и 19 удалено
  1. 0 1
      package.json
  2. 1 13
      resource/js/legacy/crowi.js
  3. 1 1
      resource/js/util/markdown-it/header-line-number.js
  4. 0 4
      yarn.lock

+ 0 - 1
package.json

@@ -83,7 +83,6 @@
     "express-session": "~1.15.0",
     "express-webpack-assets": "^0.1.0",
     "file-loader": "^1.1.0",
-    "get-line-from-pos": "^1.0.0",
     "googleapis": "^25.0.0",
     "graceful-fs": "^4.1.11",
     "i18next": "^10.0.1",

+ 1 - 13
resource/js/legacy/crowi.js

@@ -5,7 +5,6 @@
 const io = require('socket.io-client');
 const entities = require("entities");
 const escapeStringRegexp = require('escape-string-regexp');
-const getLineFromPos = require('get-line-from-pos');
 require('bootstrap-sass');
 require('jquery.cookie');
 
@@ -26,18 +25,7 @@ Crowi.createErrorView = function(msg) {
 Crowi.appendEditSectionButtons = function(contentId, markdown) {
   const $content = $(contentId || '#revision-body-content');
   $('h1,h2,h3,h4,h5,h6', $content).each(function(idx, elm) {
-    // get header text string
-    const text = $(this).text();
-    const escapedText = escapeStringRegexp(text);
-
-    // search pos for '# ...'
-    // https://regex101.com/r/y5rpO5/1
-    const regexp = new RegExp(`[^\r\n]*#+[^\r\n]*${escapedText}[^\r\n]*`);
-    let position = markdown.search(regexp);
-    if (position < 0) { // if not found, search with header text only
-      position = markdown.search(text);
-    }
-    const line = getLineFromPos(markdown, position);
+    const line = +elm.getAttribute('data-line');
 
     // add button
     $(this).append(`

+ 1 - 1
resource/js/util/markdown-it/header-line-number.js

@@ -23,7 +23,7 @@ export default class HeaderLineNumberConfigurer {
   injectLineNumbers(tokens, idx, options, env, slf) {
     var line;
     if (tokens[idx].map && tokens[idx].level === 0) {
-      line = tokens[idx].map[0];
+      line = tokens[idx].map[0] + 1;    // add 1 to convert to line number
       tokens[idx].attrJoin('class', 'line');
       tokens[idx].attrSet('data-line', String(line));
     }

+ 0 - 4
yarn.lock

@@ -2583,10 +2583,6 @@ get-func-name@^2.0.0:
   version "2.0.0"
   resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41"
 
-get-line-from-pos@^1.0.0:
-  version "1.0.0"
-  resolved "https://registry.yarnpkg.com/get-line-from-pos/-/get-line-from-pos-1.0.0.tgz#e3ca483035eef374ad40fff4d43df3fa2da328b3"
-
 get-stdin@^4.0.1:
   version "4.0.1"
   resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe"