-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doesn't work well with Obsidian's tags #410
Comments
This might be something to report to kramdown the markdown parser used by markdownlint. When I parse your markdown file by kramdown and print it to the screen as HTML via a ruby script #!/usr/bin/env ruby
require 'kramdown'
puts Kramdown::Document.new("# Heading 1
## Heading 2
- #tag Something!
### Heading 3
- Something else!").to_html I get the following output: <h1 id="heading-1">Heading 1</h1>
<h2 id="heading-2">Heading 2</h2>
<ul>
<li>
<h1 id="tag-something">tag Something!</h1>
</li>
</ul>
<h3 id="heading-3">Heading 3</h3>
<ul>
<li>Something else!</li>
</ul> This means that kramdown incorrectly identifies this tag as a headline. The parsing seems to work normally if When I add an empty HTML comment - <!---->#tag Something! the warning goes away, but the generated HTML content contains an extra paragraph <ul>
<li>
<!---->
<p>#tag Something!</p>
</li>
</ul> After adding another word in the list entry in front of the tag - text #tag Something! generates the expected HTML list <ul>
<li>Text #tag Something!</li>
</ul> In both cases, markdownlint does not report any errors. |
I submitted an issue for Kramdown. But after reading about Kramdown's syntax (which is a bit different from "regular" Markdown), especially the part about lists, which apparently allow nesting headers inside list items, I'm afraid that this might be "intended behavior", so it might not be fixed. I'm happy with "standard" Markdown, any "additions" on top of that just complicate things, IMO... Unfortunately, if this won't be fixed, it would mean that I can't really use Markdownlint, because I very often start list items with a tag (which makes the tag much more visible for long list items, and aligns them nicely if multiple list items use the same tag). I guess I could write a wrapper script, which would replace all occurrences of EDIT: |
Currently we use a "custom" flavor of markdown with Kramdown, it's the default with a few monkeypatches. But Kramdown supports GH-flavorered markdown, and I've long wanted to move us to that, as I think it's effectively the dominant one now and more flexible. DUnno if that would help in this case or not... but figured I'd mention it. Anyway, it'd be a backward-incompatible change, so we'd have to bump a major version and it's a fair amount of surgery to undo a bunch of other things, but I think it'd clean up the code base significantly. |
As I was expecting, the Kramdown issue was closed... I'm "mixing Markdown libraries" by using Markdownlint with Obsidian (which is technically true). 🤷 For now, instead of using My current linting script, in case anyone reading is interested: #!/bin/bash
trap 'trap - INT; exit $((128 + $(kill -l INT)))' INT
if ! command -v mdl > /dev/null 2>&1; then
echo "Installing mdl (Markdown linter)..."
if ! command -v gem > /dev/null 2>&1; then
>&2 echo "ERROR: gem not found (please install Ruby, e.g. run install-rvm)"
exit 64
fi
gem install mdl || exit 65
fi
find . -type f -name '*.md' \
-not -path './templates/*' \
-not -name 'UNLINKED FILES.md' \
-not -name 'UNRESOLVED LINKS.md' \
| while read -r filename; \
do \
output="$(sed -r 's/(#+[^# ])/\\\1/g' "$filename" | mdl | grep -v -e 'docs/RULES.md' | sort -h)"; \
[ -n "$output" ] && echo "$filename: $output" && echo; \
done I'm also removing the line with The above works well enough for my purposes, but I'll leave this issue open, if you're planning to move to GitHub Flavored Markdown at some point (where the list item case isn't a problem, which is mostly what I care about). |
@kankaristo , there is a plugin that is working on the linting and correction of inconsistencies in an Obsidian vault. It is called https://github.com/platers/obsidian-linter. As a disclaimer, I am helping maintain it. It is not entirely feature comparable with |
@pjkaufman, looks interesting, I'll check it out! Although, based on the GIF in the readme, it looks like it automatically formats, instead of "just" linting? I would prefer for a linter to only show me what's wrong (like |
Gotcha. That makes sense. It may be something to add in the future would be a setting to allow it to use a yellow underline in a warning mode and have another option to allow for automatically fixing the warnings. |
Description
Some of
mdl
's rules don't work well with the tags that are used in Obsidian.Environment
MDL Version: 0.11.0
Expected Behavior
Obsidian uses
#
for tags (which is a bit dangerous, since#
is also used for headings, but that's what they've chosen to use). Tags look like this:The tags are
#
followed by anything alphanumeric (but can't be all numbers), with-
or_
as a separator.If I have a Markdown file like this:
I would expect it to pass (it's legal Markdown and uses a tag).
Actual Behavior
However, I get the following rules failing:
So,
#tag
is parsed as a heading, even though it's not one. If the tag is removed, the file passes fine.I know that tags aren't a "standard" Markdown thing, but as far as I know, they're not illegal Markdown either, and Obsidian has a growing user base (it's still pre-v1).
Tags like this could also appear in "regular" text outside of their use in Obsidian, if you're mentioning a channel on IRC/Slack/Discord, or a hashtag on social media.
I'm aware of MD018, but I've never used a Markdown parser/editor that actually allows headings like that.
Replication Case
Create a Markdown file, name it
test.md
:Then run:
mdl test.md
The text was updated successfully, but these errors were encountered: