marktag 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in marktag.gemspec
4
+ gemspec
@@ -0,0 +1,32 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'minitest' do
5
+ # with Minitest::Unit
6
+ watch(%r|^test/(.*)\/?test_(.*)\.rb|)
7
+ watch(%r|^lib/marktag.rb|) { |m| "test/test_marktag.rb" }
8
+ watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
9
+ watch(%r|^test/test_helper\.rb|) { "test" }
10
+
11
+ # with Minitest::Spec
12
+ # watch(%r|^spec/(.*)_spec\.rb|)
13
+ # watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
14
+ # watch(%r|^spec/spec_helper\.rb|) { "spec" }
15
+
16
+ # Rails 3.2
17
+ # watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/controllers/#{m[1]}_test.rb" }
18
+ # watch(%r|^app/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}_test.rb" }
19
+ # watch(%r|^app/models/(.*)\.rb|) { |m| "test/unit/#{m[1]}_test.rb" }
20
+
21
+ # Rails
22
+ # watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/functional/#{m[1]}_test.rb" }
23
+ # watch(%r|^app/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}_test.rb" }
24
+ # watch(%r|^app/models/(.*)\.rb|) { |m| "test/unit/#{m[1]}_test.rb" }
25
+ end
26
+
27
+ guard :shell do
28
+ watch("lib/marktag.rb") { |m|
29
+ system "gem build marktag.gemspec"
30
+ system "gem install --no-ri --no-rdoc marktag-0.0.1.gem"
31
+ }
32
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Taku Okawa
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,81 @@
1
+ # Marktag
2
+
3
+ ## What is this program for
4
+
5
+ This is to hadd markdown support for Vim Tagbar plugin.
6
+ It generates ctags file for markdown document.
7
+
8
+ ![tagbar](https://github.com/t4ku/marktag/raw/master/screenshot.png "screenshot")
9
+
10
+ ## About Ctags and Vim Tagbar plugin
11
+
12
+ Tagbar is a vim plugin that helps navigating within file
13
+ using ctags. Currently, Tagbar support markdown file through ctags language definition.
14
+ And it doesn't support nesting headers.
15
+
16
+ ~/.ctags
17
+ ```
18
+ --langdef=markdown
19
+ --langmap=markdown:.mkd
20
+ --regex-markdown=/^#[ \t]+(.*)/\1/h,Heading_L1/
21
+ --regex-markdown=/^##[ \t]+(.*)/\1/i,Heading_L2/
22
+ --regex-markdown=/^###[ \t]+(.*)/\1/k,Heading_L3/
23
+ ```
24
+
25
+ ~/.vimrc
26
+ ```
27
+ let g:tagbar_type_markdown = {
28
+ \ 'ctagstype' : 'markdown',
29
+ \ 'kinds' : [
30
+ \ 'h:Heading_L1',
31
+ \ 'i:Heading_L2',
32
+ \ 'k:Heading_L3'
33
+ \ ]
34
+ \ }
35
+ ```
36
+ See [Support for additional types](https://github.com/majutsushi/tagbar/wiki)
37
+
38
+ Since Tagbar can be conigured to use different
39
+ program to generate tag files, I made this script to
40
+ generate tag file Tabgar is happy with.
41
+
42
+ ## Install
43
+
44
+ Install the gems.
45
+
46
+ ```
47
+ $ gem install marktag
48
+ ```
49
+
50
+ Add following in your ~/.vimrc
51
+
52
+ ```
53
+ if executable('marktag')
54
+ let g:tagbar_type_markdown = {
55
+ \ 'ctagstype' : 'markdown',
56
+ \ 'ctagsbin' : 'marktag',
57
+ \ 'kinds' : [
58
+ \ 'h:header'
59
+ \ ],
60
+ \ 'sro' : '.',
61
+ \ 'kind2scope' : {
62
+ \ 'h' : 'header'
63
+ \ },
64
+ \ 'scope2kind' : {
65
+ \ 'header' : 'h'
66
+ \ }
67
+ \ }
68
+ end
69
+ ```
70
+
71
+ ## Usage
72
+
73
+ TODO: Write usage instructions here
74
+
75
+ ## Contributing
76
+
77
+ 1. Fork it
78
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
79
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
80
+ 4. Push to the branch (`git push origin my-new-feature`)
81
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ require "marktag"
2
+
3
+ MarkTag.run(ARGV)
Binary file
@@ -0,0 +1,111 @@
1
+ require "marktag/version"
2
+ require "redcarpet"
3
+
4
+ module MarkTag
5
+ class << self
6
+ def get_renderer
7
+ return Redcarpet::Markdown.new(ParserProxy::HeaderFilter)
8
+ end
9
+
10
+ def run(args)
11
+ if args.size > 0
12
+ file = args.last
13
+ if File.exists?(file)
14
+ markdown = File.read(file)
15
+ renderer = get_renderer()
16
+ # get TagRenderer from Redcarpet postprocess hook
17
+ tag_renderer = renderer.render(markdown)
18
+ # print tag file with given file path
19
+ print tag_renderer.render(file)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ module ParserProxy
26
+ class HeaderProxy
27
+ class <<self
28
+ attr_accessor :headers
29
+ def init_document
30
+ @headers = []
31
+ end
32
+
33
+ def push(header_args)
34
+ @headers.push(header_args)
35
+ end
36
+ end
37
+ end
38
+ #
39
+ # Redcarpet::Render::HTML
40
+ #
41
+ # https://github.com/vmg/redcarpet
42
+ # How to extend the redcarpet 2 Markdown library?
43
+ # http://dev.af83.com/2012/02/27/howto-extend-the-redcarpet2-markdown-lib.html
44
+
45
+ class HeaderFilter < Redcarpet::Render::HTML
46
+ def header(header,header_level)
47
+ unless @proxy
48
+ @proxy = HeaderProxy
49
+ @proxy.init_document
50
+ end
51
+ @proxy.push([header,header_level])
52
+ # unless we want html output, we don't have to return anything
53
+ nil
54
+ end
55
+
56
+ # RedCarpet Post-process hook
57
+ def postprocess(doc)
58
+ TagRenderer.new(@proxy.headers)
59
+ end
60
+ end
61
+ end
62
+
63
+ class TagRenderer
64
+ def initialize(headers)
65
+ @headers = headers
66
+ end
67
+
68
+ def render(file_path)
69
+ tag = ""
70
+ level_headers = []
71
+ @headers.each_with_index do |header,idx|
72
+ level = header.last - 1
73
+ level_headers[level] = header.first
74
+ name = header.first
75
+
76
+ header_identifier = get_header_identifier(level_headers,level)
77
+ # esq_name = name.gsub(/\s/,"_")
78
+ esq_name = name
79
+
80
+ if (header_identifier)
81
+ tag += "#{esq_name}\t#{file_path}\t/^\\.\\*#{name}$/;\"\th\t#{header_identifier}"
82
+ else
83
+ tag += "#{esq_name}\t#{file_path}\t/^\\.\\*#{name}$/;\"\th"
84
+ end
85
+
86
+ tag += "\n"
87
+ end
88
+ return tag
89
+ end
90
+
91
+ def get_header_identifier(level_headers,target_level)
92
+ if (target_level) == 0
93
+ return nil
94
+ end
95
+
96
+ identifiers = []
97
+ (target_level -1).downto(0) do |l|
98
+ identifier = level_headers.values_at(l) != nil ? level_headers[l] : "none"
99
+ identifiers.push(identifier)
100
+ end
101
+
102
+ ctag_class = "header:"
103
+ header_str = identifiers.reverse.map do |i|
104
+ i
105
+ #i.gsub(/\s/,"_")
106
+ end.join "."
107
+
108
+ return ctag_class + header_str
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,3 @@
1
+ module Marktag
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'marktag/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "marktag"
8
+ gem.version = Marktag::VERSION
9
+ gem.authors = ["Taku Okawa"]
10
+ gem.email = ["taku.okawa@gmail.com"]
11
+ gem.description = %q{Write a gem description}
12
+ gem.summary = %q{Write a gem summary}
13
+ gem.homepage = ""
14
+
15
+ gem.add_dependency('redcarpet')
16
+
17
+ gem.add_development_dependency('guard')
18
+ gem.add_development_dependency('guard-minitest')
19
+ gem.add_development_dependency('guard-shell')
20
+
21
+ gem.files = `git ls-files`.split($/)
22
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
23
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
24
+ gem.require_paths = ["lib"]
25
+ end
@@ -0,0 +1,16 @@
1
+ if executable('marktag')
2
+ let g:tagbar_type_markdown = {
3
+ \ 'ctagstype' : 'markdown',
4
+ \ 'ctagsbin' : 'marktag',
5
+ \ 'kinds' : [
6
+ \ 'h:header'
7
+ \ ],
8
+ \ 'sro' : '.',
9
+ \ 'kind2scope' : {
10
+ \ 'h' : 'header'
11
+ \ },
12
+ \ 'scope2kind' : {
13
+ \ 'header' : 'h'
14
+ \ }
15
+ \ }
16
+ end
@@ -0,0 +1,9 @@
1
+ if executable('marktag')
2
+ let g:tagbar_type_markdown = {
3
+ \ 'ctagsbin' : 'marktag',
4
+ \ 'ctagstype' : 'markdown',
5
+ \ 'kinds' : [
6
+ \ 'h:Heading'
7
+ \ ]
8
+ \ }
9
+ endif
Binary file
@@ -0,0 +1,82 @@
1
+ require "marktag"
2
+ require "minitest/autorun"
3
+
4
+
5
+ class HeaderFilterTest < MiniTest::Unit::TestCase
6
+ def test_filter_capture_all_headers
7
+ md = Redcarpet::Markdown.new(MarkTag::ParserProxy::HeaderFilter)
8
+
9
+ md_text = <<-EOS
10
+ first header
11
+ ============
12
+
13
+ second header
14
+ ------------
15
+
16
+ ### third header
17
+ EOS
18
+
19
+ md_tag = <<-EOS
20
+ first_header lib/marktag.rb /^first header$/;" h
21
+ second_header lib/marktag.rb /^second header$/;" h header:first_header
22
+ third_header lib/marktag.rb /^third header$/;" h header:first_header:second_header
23
+ EOS
24
+
25
+ # This is the tag file of this ruby script
26
+ #
27
+ # Document lib/marktag.rb /^ module Document$/;" m class:MarkTag
28
+ # Element lib/marktag.rb /^ class Element$/;" c class:MarkTag.Document
29
+ # MarkTag lib/marktag.rb /^module MarkTag$/;" m
30
+ # ...
31
+ #
32
+ # In the case of
33
+ # Markdown Title > Tutorial > ctags file format
34
+ #
35
+ # Markdown Title path/to/markdown /^Markdown Title$/;" heading
36
+ # Tutorial path/to/markdown /^Tutorial$/;" h heading:Markdown Title
37
+ # ctags file format path/to/markdown /^ctags file format$/;" h heading:Markdown Title.Tutorial
38
+ #
39
+ # Exuberant Ctags
40
+ # http://en.wikipedia.org/wiki/Ctags#Exuberant_Ctags_2
41
+ # {tagname}<Tab>{tagfile}<Tab>{tagaddress}[;"<Tab>{tagfield}...]
42
+
43
+ assert_equal md_tag,md.render(md_text)
44
+ end
45
+
46
+ def test_headers_with_paragrahs
47
+ md = Redcarpet::Markdown.new(MarkTag::ParserProxy::HeaderFilter)
48
+
49
+ md_text = <<-EOS
50
+ first header
51
+ ============
52
+
53
+ first paragraph
54
+
55
+ second header
56
+ ------------
57
+
58
+ second paragraph
59
+
60
+ ### third header
61
+
62
+ third paragraph
63
+
64
+ EOS
65
+
66
+ md_tag = <<-EOS
67
+ first_header lib/marktag.rb /^first header$/;" h
68
+ second_header lib/marktag.rb /^second header$/;" h header:first_header
69
+ third_header lib/marktag.rb /^third header$/;" h header:first_header:second_header
70
+ EOS
71
+
72
+ assert_equal md_tag,md.render(md_text)
73
+ end
74
+
75
+ def test_invalid_sequence_of_headers
76
+ end
77
+ end
78
+
79
+ class RendererTest < MiniTest::Unit::TestCase
80
+ def setup
81
+ end
82
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: marktag
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Taku Okawa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: redcarpet
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: guard
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: guard-minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-shell
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Write a gem description
79
+ email:
80
+ - taku.okawa@gmail.com
81
+ executables:
82
+ - marktag
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - Gemfile
88
+ - Guardfile
89
+ - LICENSE.txt
90
+ - README.md
91
+ - Rakefile
92
+ - bin/marktag
93
+ - lib/.marktag.rb.swp
94
+ - lib/marktag.rb
95
+ - lib/marktag/version.rb
96
+ - marktag.gemspec
97
+ - marktag.vim
98
+ - plugin/tagbar-markdown.vim
99
+ - screenshot.png
100
+ - test/test_marktag.rb
101
+ homepage: ''
102
+ licenses: []
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 1.8.23
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: Write a gem summary
125
+ test_files:
126
+ - test/test_marktag.rb
127
+ has_rdoc: