Skip to content
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

Added support for foldable, atx-style markdown headings (#); plus listing of images, and tables #177

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/.ctags
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@
--langmap=Markdown:+.mkd
--langmap=Markdown:+.mkdown
--langmap=Markdown:+.ron
--regex-Markdown=/^#+[ \t]*([^#]+)/\1/f,function/
--regex-Markdown=/^#{1}[ \t]*([^#]+)/\1/a,header-1/
--regex-Markdown=/^#{2}[ \t]*([^#]+)/\1/b,header-2/
--regex-Markdown=/^#{3}[ \t]*([^#]+)/\1/c,header-3/
--regex-Markdown=/^#{4}[ \t]*([^#]+)/\1/d,header-4/
--regex-Markdown=/^#{5}[ \t]*([^#]+)/\1/e,header-5/
--regex-Markdown=/^#{6}[ \t]*([^#]+)/\1/f,header-6/
--regex-Markdown=/!\[(.*)\]\(.*\)/\1/x,image/
--regex-Markdown=/^[ \t]*Table: (.*)/\1/y,table/

--langdef=Json
--langmap=Json:.json
Expand Down
31 changes: 30 additions & 1 deletion lib/tag-parser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ module.exports =
parents[now].parent = pre
parents[now].name = @splitNameTag(parents[now].name)

buildMarkdownParents: (parents) ->
# identify the header level if any
headerlevel = (x) -> parseInt(x.type.slice(-1), 10)

last_hierarchy_level = false;
last_hierarchy = [false]

for tag in @tags
taglevel = headerlevel(tag)
if taglevel > 0
tag.parent = last_hierarchy[taglevel - 2] if taglevel >= 2 # 'header-1' without parent
if taglevel - last_hierarchy_level > 1 # missing hierarchy level in between
tag.parent = last_hierarchy.slice(-1)[0]
tag.hierarchy_break = true
last_hierarchy_level = taglevel
last_hierarchy[taglevel-1] = tag.parentKey
last_hierarchy = last_hierarchy.slice(0, taglevel) # crop lower levels of hierarchy
else # NaN -> table, image
tag.parent = last_hierarchy[last_hierarchy_level-1]

parse: ->
roots = []
parents = {}
Expand All @@ -79,11 +99,16 @@ module.exports =
key = tag.type + ':' + parent + @splitSymbol + tag.name
else
key = tag.type + ':' + tag.name
# add row number to avoid issues in markdown documents with repeating heading names
key = tag.type + ':' + tag.position.row + ':' + tag.name if @grammar == 'source.gfm' or @grammar == 'text.md'
tag.parentKey = key # store for consistency
parents[key] = tag

# try to build up the missed parent
@buildMissedParent(parents)

@buildMarkdownParents() if @grammar == 'source.gfm' or @grammar == 'text.md'

for tag in @tags
if tag.parent
parent = parents[tag.parent]
Expand All @@ -96,6 +121,7 @@ module.exports =
for tag in @tags
tag.label = tag.name
tag.icon = "icon-#{tag.type}"
tag.icon += " icon-hierarchy-break" if tag.hierarchy_break
if tag.parent
parent = parents[tag.parent]
parent.children ?= []
Expand All @@ -104,7 +130,10 @@ module.exports =
roots.push(tag)
types[tag.type] = null

return {root: {label: 'root', icon: null, children: roots}, types: Object.keys(types)}
types = Object.keys(types)
types = types.sort() if @grammar == 'source.gfm' or @grammar == 'text.md'

return {root: {label: 'root', icon: null, children: roots}, types: types}

getNearestTag: (row) ->
left = 0
Expand Down
50 changes: 50 additions & 0 deletions styles/symbols-tree-view.less
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,56 @@
content: @@name;
}

.symbols-tree-view .icon-hierarchy-break::after {
content: " ⚠";
font-size: 120%;
}

.symbols-tree-view .icon-header-1::before {
content: '⚫';
font-size: 140%;
}
.symbols-tree-view .icon-header-1 {
font-weight: bold;
font-size: 120%;
}

.symbols-tree-view .icon-header-2::before {
content: '⚫';
font-size: 120%;
}
.symbols-tree-view .icon-header-2 {
font-size: 120%;
}

.symbols-tree-view .icon-header-3::before {
content: '♦';
font-size: 120%;
}

.symbols-tree-view .icon-header-4::before {
content: '④';
font-size: 120%;
}

.symbols-tree-view .icon-header-5::before {
content: '⑤';
font-size: 120%;
}

.symbols-tree-view .icon-header-6::before {
content: '⑥';
font-size: 120%;
}

.symbols-tree-view .icon-image::before {
content: '★';
}

.symbols-tree-view .icon-table::before {
content: '☷';
}

.symbols-tree-view .icon-function::before {
.symbol-icon(symbol-function);
}
Expand Down