Compare commits
No commits in common. "d584fe8bf7256e6d7168c0e7ec59fba8f35baf3a" and "3d249dde05824fc1302a47f5731b7fca7dffbad1" have entirely different histories.
d584fe8bf7
...
3d249dde05
|
|
@ -1,56 +0,0 @@
|
||||||
'use strict'
|
|
||||||
|
|
||||||
var util = require('util')
|
|
||||||
|
|
||||||
function Plugin(options) {
|
|
||||||
var self = function (md) {
|
|
||||||
self.options = options
|
|
||||||
self.init(md)
|
|
||||||
}
|
|
||||||
|
|
||||||
self.__proto__ = Plugin.prototype
|
|
||||||
self.id = 'markdown-tag'
|
|
||||||
|
|
||||||
return self
|
|
||||||
}
|
|
||||||
|
|
||||||
util.inherits(Plugin, Function)
|
|
||||||
|
|
||||||
Plugin.prototype.init = function (md) {
|
|
||||||
md.inline.ruler.push(this.id, this.parse.bind(this))
|
|
||||||
md.renderer.rules[this.id] = this.render.bind(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function tagParser(id, state, silent) {
|
|
||||||
let input = state.src.slice(state.pos);
|
|
||||||
|
|
||||||
const match = /^#[^ ]+/.exec(input)
|
|
||||||
if (!match) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(match)
|
|
||||||
const prefixLength = match[0].length
|
|
||||||
if (!silent) {
|
|
||||||
console.log(state.src, state.pos, prefixLength)
|
|
||||||
let link = state.src.slice(state.pos + 1, state.pos + prefixLength)
|
|
||||||
let token = state.push(id, '', 0)
|
|
||||||
token.meta = {match: link, tag: true}
|
|
||||||
console.log(token)
|
|
||||||
}
|
|
||||||
state.pos += prefixLength
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
Plugin.prototype.parse = function (state, silent) {
|
|
||||||
return tagParser(this.id, state, silent)
|
|
||||||
}
|
|
||||||
|
|
||||||
Plugin.prototype.render = function (tokens, id, options, env) {
|
|
||||||
let {match: link} = tokens[id].meta
|
|
||||||
return '<a href="' + this.options.relativeBaseURL + encodeURIComponent(link) + '" class="tag">' + '#' + link + '</a>';
|
|
||||||
}
|
|
||||||
|
|
||||||
export default (options) => {
|
|
||||||
return Plugin(options);
|
|
||||||
}
|
|
||||||
|
|
@ -3,7 +3,6 @@ import MarkdownItWikilinks2 from "./wikilinks2";
|
||||||
import MarkdownItMetadata from "./metadatalinks";
|
import MarkdownItMetadata from "./metadatalinks";
|
||||||
import MarkdownItMark from "markdown-it-mark";
|
import MarkdownItMark from "markdown-it-mark";
|
||||||
import MarkdownItKatex from "markdown-it-katex";
|
import MarkdownItKatex from "markdown-it-katex";
|
||||||
import MarkdownItTag from "./markdown-tag";
|
|
||||||
|
|
||||||
const MD = new MarkdownIt({
|
const MD = new MarkdownIt({
|
||||||
linkify: true,
|
linkify: true,
|
||||||
|
|
@ -31,9 +30,6 @@ MD.use(MarkdownItMetadata())
|
||||||
// class: 'wiki-link'
|
// class: 'wiki-link'
|
||||||
// },
|
// },
|
||||||
// }))
|
// }))
|
||||||
MD.use(MarkdownItMark).use(MarkdownItKatex)
|
// MD.use(MarkdownItMark).use(MarkdownItKatex)
|
||||||
MD.use(MarkdownItTag({
|
|
||||||
relativeBaseURL: '/edit/',
|
|
||||||
}))
|
|
||||||
|
|
||||||
export default MD;
|
export default MD;
|
||||||
|
|
|
||||||
|
|
@ -203,15 +203,15 @@ mark {
|
||||||
outline: 4px solid #ffff99;
|
outline: 4px solid #ffff99;
|
||||||
}
|
}
|
||||||
|
|
||||||
//.root mark::before {
|
.root mark::before {
|
||||||
// content: "==";
|
content: "==";
|
||||||
// color: #999;
|
color: #999;
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//.root mark::after {
|
.root mark::after {
|
||||||
// content: "==";
|
content: "==";
|
||||||
// color: #999;
|
color: #999;
|
||||||
//}
|
}
|
||||||
|
|
||||||
.marker, .fold {
|
.marker, .fold {
|
||||||
user-select: none;
|
user-select: none;
|
||||||
|
|
@ -676,9 +676,6 @@ input.input-line, input.input-line:active {
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
padding: 2px 4px;
|
padding: 2px 4px;
|
||||||
}
|
}
|
||||||
.backrefs .tag {
|
|
||||||
background: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.review {
|
.review {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
18
util.go
18
util.go
|
|
@ -132,8 +132,7 @@ func ParseLinks(blockId string, content string) ([]ParsedLink, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseTags(content string) ([]string, error) {
|
func ParseTags(content string) ([]string, error) {
|
||||||
linkRE := regexp.MustCompile(`(#\[\[\s*([^\]]+)\s*\]\])`)
|
hrefRE := regexp.MustCompile(`(#\[\[\s*([^\]]+)\s*\]\])`)
|
||||||
tagRE := regexp.MustCompile(`#([^ ]+)`)
|
|
||||||
|
|
||||||
scanner := bufio.NewScanner(strings.NewReader(content))
|
scanner := bufio.NewScanner(strings.NewReader(content))
|
||||||
scanner.Split(bufio.ScanLines)
|
scanner.Split(bufio.ScanLines)
|
||||||
|
|
@ -142,16 +141,13 @@ func ParseTags(content string) ([]string, error) {
|
||||||
|
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
links := linkRE.FindAllStringSubmatch(line, -1)
|
links := hrefRE.FindAllStringSubmatch(line, -1)
|
||||||
for _, matches := range links {
|
for _, matches := range links {
|
||||||
linkText := matches[0]
|
link := matches[0]
|
||||||
linkText = strings.TrimPrefix(linkText, "#[[")
|
link = strings.TrimPrefix(link, "#[[")
|
||||||
linkText = strings.TrimSuffix(linkText, "]]")
|
link = strings.TrimSuffix(link, "]]")
|
||||||
linkText = strings.TrimSpace(linkText)
|
link = strings.TrimSpace(link)
|
||||||
result = append(result, linkText)
|
result = append(result, link)
|
||||||
}
|
|
||||||
for _, matches := range tagRE.FindAllStringSubmatch(line, -1) {
|
|
||||||
result = append(result, matches[1])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user