Compare commits
16 Commits
Author | SHA1 | Date |
---|---|---|
Nick Dumas | 9b72dac5c8 | 1 year ago |
Nick Dumas | a932fdefc9 | 1 year ago |
Nick Dumas | dc04526e49 | 1 year ago |
Nick Dumas | 93149522cb | 1 year ago |
Nick Dumas | a68b4b5cbf | 1 year ago |
Nick Dumas | e5650fb492 | 1 year ago |
Nick Dumas | c5d366f7b7 | 1 year ago |
Nick Dumas | 248298cced | 1 year ago |
Nick Dumas | 20cc70b47b | 1 year ago |
Nick Dumas | 9db278952d | 1 year ago |
Nick Dumas | 4da393060f | 1 year ago |
Nick Dumas | 61f1d12e77 | 1 year ago |
Nick Dumas | e1486ea2d7 | 1 year ago |
Nick Dumas | e26cc2106d | 1 year ago |
Nick Dumas | 3c180eb02c | 1 year ago |
Nick Dumas | a366cf4e5a | 1 year ago |
@ -1 +1,27 @@
|
||||
common --experimental_enable_bzlmod
|
||||
|
||||
# Disable lockfiles until it works properly.
|
||||
# https://github.com/bazelbuild/bazel/issues/19068
|
||||
common --lockfile_mode=off
|
||||
|
||||
###############################
|
||||
# Directory structure #
|
||||
###############################
|
||||
|
||||
# Artifacts are typically placed in a directory called "dist"
|
||||
# Be aware that this setup will still create a bazel-out symlink in
|
||||
# your project directory, which you must exclude from version control and your
|
||||
# editor's search path.
|
||||
build --symlink_prefix=dist/
|
||||
|
||||
###############################
|
||||
# Output #
|
||||
###############################
|
||||
|
||||
# A more useful default output mode for bazel query, which
|
||||
# prints "ng_module rule //foo:bar" instead of just "//foo:bar".
|
||||
query --output=label_kind
|
||||
|
||||
# By default, failing tests don't print any output, it's logged to a
|
||||
# file instead.
|
||||
test --test_output=errors
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
// "fmt"
|
||||
|
||||
ofm "code.ndumas.com/ndumas/obsidian-markdown/goldmark"
|
||||
"github.com/yuin/goldmark"
|
||||
"github.com/yuin/goldmark/parser"
|
||||
)
|
||||
|
||||
func main() {
|
||||
m := goldmark.New(goldmark.WithExtensions(
|
||||
ofm.ObsidianLinkExtension,
|
||||
))
|
||||
|
||||
source := `
|
||||
# Hello goldmark-extensions
|
||||
this is a [[wikilink]] in text
|
||||
|
||||
[[wikilink]] starting a line
|
||||
|
||||
ending a line with a [[wikilink]]
|
||||
`
|
||||
|
||||
var buf bytes.Buffer
|
||||
|
||||
context := parser.NewContext()
|
||||
|
||||
err := m.Convert([]byte(source), &buf, parser.WithContext(context))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// fmt.Printf("%#+v\n", context)
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
package goldmark
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
// "errors"
|
||||
"regexp"
|
||||
|
||||
"github.com/yuin/goldmark"
|
||||
"github.com/yuin/goldmark/ast"
|
||||
"github.com/yuin/goldmark/parser"
|
||||
"github.com/yuin/goldmark/text"
|
||||
"github.com/yuin/goldmark/util"
|
||||
)
|
||||
|
||||
var contextKeyMeta = parser.NewContextKey()
|
||||
|
||||
func isSeparator(line []byte) bool {
|
||||
r := regexp.MustCompile(`^\s*-{3,}\s*$`)
|
||||
|
||||
return r.Match(line)
|
||||
}
|
||||
|
||||
type obsidianLinkParser struct{}
|
||||
|
||||
var defaultLinkParser = &obsidianLinkParser{}
|
||||
|
||||
func (b *obsidianLinkParser) Trigger() []byte {
|
||||
// return []byte{'!', '[', ']'}
|
||||
fmt.Println("obsidianLinkParser.Trigger()")
|
||||
return []byte{'[', ']'}
|
||||
}
|
||||
|
||||
func (b *obsidianLinkParser) Parse(parent ast.Node, block text.Reader, pc parser.Context) ast.Node {
|
||||
fmt.Println("obsidianLinkParser.Parse()")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *obsidianLinkParser) Open(parent ast.Node, block text.Reader, pc parser.Context) (ast.Node, parser.State) {
|
||||
fmt.Println("obsidianLinkParser.Open()")
|
||||
linenum, _ := block.Position()
|
||||
if linenum != 0 {
|
||||
return nil, parser.NoChildren
|
||||
}
|
||||
|
||||
line, _ := block.PeekLine()
|
||||
|
||||
if isSeparator(line) {
|
||||
return ast.NewTextBlock(), parser.NoChildren
|
||||
}
|
||||
|
||||
return nil, parser.NoChildren
|
||||
}
|
||||
|
||||
func (b *obsidianLinkParser) Continue(node ast.Node, reader text.Reader, pc parser.Context) parser.State {
|
||||
line, segment := reader.PeekLine()
|
||||
|
||||
if isSeparator(line) {
|
||||
reader.Advance(segment.Len())
|
||||
|
||||
return parser.Close
|
||||
}
|
||||
|
||||
node.Lines().Append(segment)
|
||||
|
||||
return parser.Continue | parser.NoChildren
|
||||
}
|
||||
|
||||
func (b *obsidianLinkParser) Close(node ast.Node, reader text.Reader, pc parser.Context) {
|
||||
lines := node.Lines()
|
||||
|
||||
var buf bytes.Buffer
|
||||
|
||||
for i := 0; i < lines.Len(); i++ {
|
||||
segment := lines.At(i)
|
||||
buf.Write(segment.Value(reader.Source()))
|
||||
}
|
||||
pc.Set(contextKeyMeta, buf)
|
||||
node.Parent().RemoveChild(node.Parent(), node)
|
||||
}
|
||||
|
||||
func (b *obsidianLinkParser) CanInterruptParagraph() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (b *obsidianLinkParser) CanAcceptIndentedLine() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
type obsidianLinkExtension struct{}
|
||||
|
||||
func (ole *obsidianLinkExtension) Extend(m goldmark.Markdown) {
|
||||
m.Parser().AddOptions(
|
||||
parser.WithInlineParsers(
|
||||
util.Prioritized(defaultLinkParser, 0),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
var ObsidianLinkExtension = &obsidianLinkExtension{}
|
Loading…
Reference in New Issue