Compare commits

...

4 Commits

Author SHA1 Message Date
d584fe8bf7 Problem: tags are not really visible
All checks were successful
continuous-integration/drone/push Build is passing
Solution: show tags as tags
2022-01-17 21:06:00 +01:00
f79a01ae9b Problem: tags are not parsed server side
Solution: add parsing of tags to server side
2022-01-17 21:01:34 +01:00
71d957ae9b Problem: mark markup uses "=="
Solution: remove "==" around mark
2022-01-17 21:01:02 +01:00
27579e841e Problem: tags are not parsed on client side
Solution: parse tags in markdown
2022-01-17 20:56:37 +01:00
4 changed files with 84 additions and 17 deletions

View File

@ -0,0 +1,56 @@
'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);
}

View File

@ -3,6 +3,7 @@ import MarkdownItWikilinks2 from "./wikilinks2";
import MarkdownItMetadata from "./metadatalinks";
import MarkdownItMark from "markdown-it-mark";
import MarkdownItKatex from "markdown-it-katex";
import MarkdownItTag from "./markdown-tag";
const MD = new MarkdownIt({
linkify: true,
@ -30,6 +31,9 @@ MD.use(MarkdownItMetadata())
// class: 'wiki-link'
// },
// }))
// MD.use(MarkdownItMark).use(MarkdownItKatex)
MD.use(MarkdownItMark).use(MarkdownItKatex)
MD.use(MarkdownItTag({
relativeBaseURL: '/edit/',
}))
export default MD;

View File

@ -203,15 +203,15 @@ mark {
outline: 4px solid #ffff99;
}
.root mark::before {
content: "==";
color: #999;
}
.root mark::after {
content: "==";
color: #999;
}
//.root mark::before {
// content: "==";
// color: #999;
//}
//
//.root mark::after {
// content: "==";
// color: #999;
//}
.marker, .fold {
user-select: none;
@ -676,6 +676,9 @@ input.input-line, input.input-line:active {
border-radius: 3px;
padding: 2px 4px;
}
.backrefs .tag {
background: white;
}
.review {
}

18
util.go
View File

@ -132,7 +132,8 @@ func ParseLinks(blockId string, content string) ([]ParsedLink, error) {
}
func ParseTags(content string) ([]string, error) {
hrefRE := regexp.MustCompile(`(#\[\[\s*([^\]]+)\s*\]\])`)
linkRE := regexp.MustCompile(`(#\[\[\s*([^\]]+)\s*\]\])`)
tagRE := regexp.MustCompile(`#([^ ]+)`)
scanner := bufio.NewScanner(strings.NewReader(content))
scanner.Split(bufio.ScanLines)
@ -141,13 +142,16 @@ func ParseTags(content string) ([]string, error) {
for scanner.Scan() {
line := scanner.Text()
links := hrefRE.FindAllStringSubmatch(line, -1)
links := linkRE.FindAllStringSubmatch(line, -1)
for _, matches := range links {
link := matches[0]
link = strings.TrimPrefix(link, "#[[")
link = strings.TrimSuffix(link, "]]")
link = strings.TrimSpace(link)
result = append(result, link)
linkText := matches[0]
linkText = strings.TrimPrefix(linkText, "#[[")
linkText = strings.TrimSuffix(linkText, "]]")
linkText = strings.TrimSpace(linkText)
result = append(result, linkText)
}
for _, matches := range tagRE.FindAllStringSubmatch(line, -1) {
result = append(result, matches[1])
}
}