meta_commit_markdown_support 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +19 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/meta_commit_markdown_support.rb +35 -0
- data/lib/meta_commit_markdown_support/diffs/anchor_addition.rb +33 -0
- data/lib/meta_commit_markdown_support/diffs/anchor_deletion.rb +31 -0
- data/lib/meta_commit_markdown_support/diffs/anchor_rename.rb +35 -0
- data/lib/meta_commit_markdown_support/diffs/code_addition.rb +18 -0
- data/lib/meta_commit_markdown_support/diffs/code_change.rb +19 -0
- data/lib/meta_commit_markdown_support/diffs/code_deletion.rb +18 -0
- data/lib/meta_commit_markdown_support/diffs/diff.rb +50 -0
- data/lib/meta_commit_markdown_support/diffs/list_addition.rb +23 -0
- data/lib/meta_commit_markdown_support/diffs/list_change.rb +26 -0
- data/lib/meta_commit_markdown_support/diffs/list_deletion.rb +23 -0
- data/lib/meta_commit_markdown_support/diffs/text_addition.rb +25 -0
- data/lib/meta_commit_markdown_support/diffs/text_change.rb +27 -0
- data/lib/meta_commit_markdown_support/diffs/text_deletion.rb +25 -0
- data/lib/meta_commit_markdown_support/helpers/contextual_ast_accessor.rb +211 -0
- data/lib/meta_commit_markdown_support/locator.rb +29 -0
- data/lib/meta_commit_markdown_support/models/ast.rb +47 -0
- data/lib/meta_commit_markdown_support/parsers/markdown.rb +28 -0
- data/lib/meta_commit_markdown_support/renderer.rb +36 -0
- data/lib/meta_commit_markdown_support/version.rb +7 -0
- data/meta_commit_markdown_support.gemspec +28 -0
- metadata +159 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 95bd45c8d1f3fda94874710d001db6d4e4b35ace
|
|
4
|
+
data.tar.gz: 4c1909701fcdee3557a4c18e2b2c3b0a937afec1
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 05b2943c0f76d68d7f09605a2fe8ccd3122bcb5a94973f75601803a782f7416945532604513abeede3de995349117a7da0fff51679889e92f9c5a8627e5e2fa7
|
|
7
|
+
data.tar.gz: f81a8592e0f97aac4f0072870983cdd04b4b82ffd24a12cdc65a46df428385b5f383a38f90a70f79a93e67be2ccce7bccc6da4801e2ed9fca62afd0012bdc57b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at stasdobrovolskiy@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Stanislav Dobrovolskiy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# meta_commit markdown support
|
|
2
|
+
[](https://travis-ci.org/meta-commit/markdown_support)
|
|
3
|
+
|
|
4
|
+
This gem adds markdown language support to [meta_commit](https://github.com/usernam3/meta_commit) commands
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
Install gem :
|
|
9
|
+
|
|
10
|
+
$ gem install meta_commit_markdown_support
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
To add markdown markup language support to meta_commit runner for specific repository you need to :
|
|
15
|
+
|
|
16
|
+
- edit meta_commit.yml file of repo
|
|
17
|
+
- add `markdown_support` to list of extensions
|
|
18
|
+
|
|
19
|
+
Now meta_commit knows that repository requires markdown support and will load this gem
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "meta_commit_markdown_support"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require "meta_commit_contracts"
|
|
2
|
+
|
|
3
|
+
module MetaCommit
|
|
4
|
+
module Extensions
|
|
5
|
+
module MarkdownSupport
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
require "meta_commit_markdown_support/version"
|
|
11
|
+
require "meta_commit_markdown_support/helpers/contextual_ast_accessor"
|
|
12
|
+
|
|
13
|
+
require "meta_commit_markdown_support/models/ast"
|
|
14
|
+
|
|
15
|
+
require "meta_commit_markdown_support/parsers/markdown"
|
|
16
|
+
|
|
17
|
+
require "meta_commit_markdown_support/locator"
|
|
18
|
+
|
|
19
|
+
require "meta_commit_markdown_support/diffs/diff"
|
|
20
|
+
|
|
21
|
+
require "meta_commit_markdown_support/diffs/anchor_addition"
|
|
22
|
+
require "meta_commit_markdown_support/diffs/anchor_rename"
|
|
23
|
+
require "meta_commit_markdown_support/diffs/anchor_deletion"
|
|
24
|
+
|
|
25
|
+
require "meta_commit_markdown_support/diffs/list_addition"
|
|
26
|
+
require "meta_commit_markdown_support/diffs/list_change"
|
|
27
|
+
require "meta_commit_markdown_support/diffs/list_deletion"
|
|
28
|
+
|
|
29
|
+
require "meta_commit_markdown_support/diffs/code_addition"
|
|
30
|
+
require "meta_commit_markdown_support/diffs/code_change"
|
|
31
|
+
require "meta_commit_markdown_support/diffs/code_deletion"
|
|
32
|
+
|
|
33
|
+
require "meta_commit_markdown_support/diffs/text_addition"
|
|
34
|
+
require "meta_commit_markdown_support/diffs/text_change"
|
|
35
|
+
require "meta_commit_markdown_support/diffs/text_deletion"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module MetaCommit::Extension::MarkdownSupport::Diffs
|
|
2
|
+
class AnchorAddition < Diff
|
|
3
|
+
# @param [MetaCommit::Contracts::ChangeContext] context
|
|
4
|
+
# @return [Boolean]
|
|
5
|
+
def supports_change(context)
|
|
6
|
+
context.type == TYPE_ADDITION &&
|
|
7
|
+
contextual_ast_has_target_node(context.new_contextual_ast) &&
|
|
8
|
+
anchor_context?(context.new_contextual_ast)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# @return [String]
|
|
12
|
+
def string_representation
|
|
13
|
+
parent_anchor = change_context.new_contextual_ast
|
|
14
|
+
.context_nodes
|
|
15
|
+
.find {|node| anchor?(node)}
|
|
16
|
+
|
|
17
|
+
if !parent_anchor.children.first.nil? && text?(parent_anchor.children.first)
|
|
18
|
+
new_anchor_title = parent_anchor.element.first_child.string_content
|
|
19
|
+
parent_anchor.element.first_child.string_content
|
|
20
|
+
return "add #{new_anchor_title} link"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
if !parent_anchor.children.first.nil? && image?(parent_anchor.children.first)
|
|
24
|
+
new_anchor_title = parent_anchor.element.first_child.first_child.string_content
|
|
25
|
+
parent_anchor.element.first_child.first_child.string_content
|
|
26
|
+
return "add #{new_anchor_title}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
anchor_target = anchor_target(change_context.new_contextual_ast)
|
|
30
|
+
"delete #{anchor_target} link"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module MetaCommit::Extension::MarkdownSupport::Diffs
|
|
2
|
+
class AnchorDeletion < Diff
|
|
3
|
+
# @param [MetaCommit::Contracts::ChangeContext] context
|
|
4
|
+
# @return [Boolean]
|
|
5
|
+
def supports_change(context)
|
|
6
|
+
context.type == TYPE_DELETION &&
|
|
7
|
+
contextual_ast_has_target_node(context.old_contextual_ast) &&
|
|
8
|
+
anchor_context?(context.old_contextual_ast)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# @return [String]
|
|
12
|
+
def string_representation
|
|
13
|
+
parent_anchor = change_context.old_contextual_ast.context_nodes.find {|node| anchor?(node)}
|
|
14
|
+
|
|
15
|
+
if !parent_anchor.children.first.nil? && text?(parent_anchor.children.first)
|
|
16
|
+
new_anchor_title = parent_anchor.element.first_child.string_content
|
|
17
|
+
parent_anchor.element.first_child.string_content
|
|
18
|
+
return "delete #{new_anchor_title} link"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
if !parent_anchor.children.first.nil? && image?(parent_anchor.children.first)
|
|
22
|
+
new_anchor_title = parent_anchor.element.first_child.first_child.string_content
|
|
23
|
+
parent_anchor.element.first_child.first_child.string_content
|
|
24
|
+
return "delete #{new_anchor_title}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
anchor_target = anchor_target(change_context.old_contextual_ast)
|
|
28
|
+
"delete #{anchor_target} link"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module MetaCommit::Extension::MarkdownSupport::Diffs
|
|
2
|
+
class AnchorRename < Diff
|
|
3
|
+
# @param [MetaCommit::Contracts::ChangeContext] context
|
|
4
|
+
# @return [Boolean]
|
|
5
|
+
def supports_change(context)
|
|
6
|
+
context.type == TYPE_REPLACE &&
|
|
7
|
+
contextual_ast_has_target_node(context.old_contextual_ast) && contextual_ast_has_target_node(context.new_contextual_ast) &&
|
|
8
|
+
anchor_context?(context.old_contextual_ast) && anchor_context?(context.new_contextual_ast)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# @return [String]
|
|
12
|
+
def string_representation
|
|
13
|
+
old_links = elements_of_type_on_line(change_context.old_contextual_ast, ELEMENT_TYPE_ANCHOR, change_context.old_lineno)
|
|
14
|
+
new_links = elements_of_type_on_line(change_context.new_contextual_ast, ELEMENT_TYPE_ANCHOR, change_context.new_lineno)
|
|
15
|
+
|
|
16
|
+
closest_old_link = element_closest_to(old_links, change_context.column)
|
|
17
|
+
closest_new_link = element_closest_to(new_links, change_context.column)
|
|
18
|
+
|
|
19
|
+
if !closest_new_link.nil? && !closest_new_link.children.first.nil? && text?(closest_new_link.children.first)
|
|
20
|
+
new_anchor_title = closest_new_link.element.first_child.string_content
|
|
21
|
+
closest_new_link.element.first_child.string_content
|
|
22
|
+
return "change #{new_anchor_title} link"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
if !closest_new_link.nil? && !closest_new_link.children.first.nil? && image?(closest_new_link.children.first)
|
|
26
|
+
new_anchor_title = closest_new_link.element.first_child.first_child.string_content
|
|
27
|
+
closest_new_link.element.first_child.first_child.string_content
|
|
28
|
+
return "change #{new_anchor_title}"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
anchor_target = anchor_target(change_context.new_contextual_ast)
|
|
32
|
+
"change #{anchor_target} link"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module MetaCommit::Extension::MarkdownSupport::Diffs
|
|
2
|
+
class CodeAddition < Diff
|
|
3
|
+
# @param [MetaCommit::Contracts::ChangeContext] context
|
|
4
|
+
# @return [Boolean]
|
|
5
|
+
def supports_change(context)
|
|
6
|
+
context.type == TYPE_ADDITION &&
|
|
7
|
+
contextual_ast_has_target_node(context.new_contextual_ast) &&
|
|
8
|
+
(code_context?(context.new_contextual_ast) || code?(context.new_contextual_ast.target_node))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# @return [String]
|
|
12
|
+
def string_representation
|
|
13
|
+
first_line = code_first_line(change_context.new_contextual_ast)
|
|
14
|
+
return "add #{first_line} code sample" unless first_line.empty?
|
|
15
|
+
'add code sample'
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module MetaCommit::Extension::MarkdownSupport::Diffs
|
|
2
|
+
class CodeChange < Diff
|
|
3
|
+
# @param [MetaCommit::Contracts::ChangeContext] context
|
|
4
|
+
# @return [Boolean]
|
|
5
|
+
def supports_change(context)
|
|
6
|
+
context.type == TYPE_REPLACE &&
|
|
7
|
+
contextual_ast_has_target_node(context.new_contextual_ast) && contextual_ast_has_target_node(context.old_contextual_ast) &&
|
|
8
|
+
(code_context?(context.old_contextual_ast) || code?(context.old_contextual_ast.target_node)) &&
|
|
9
|
+
(code_context?(context.new_contextual_ast) || code?(context.new_contextual_ast.target_node))
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# @return [String]
|
|
13
|
+
def string_representation
|
|
14
|
+
first_line = code_first_line(change_context.new_contextual_ast)
|
|
15
|
+
return "change #{first_line} code sample" unless first_line.empty?
|
|
16
|
+
'change code sample'
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module MetaCommit::Extension::MarkdownSupport::Diffs
|
|
2
|
+
class CodeDeletion < Diff
|
|
3
|
+
# @param [MetaCommit::Contracts::ChangeContext] context
|
|
4
|
+
# @return [Boolean]
|
|
5
|
+
def supports_change(context)
|
|
6
|
+
context.type == TYPE_DELETION &&
|
|
7
|
+
contextual_ast_has_target_node(context.old_contextual_ast) &&
|
|
8
|
+
(code_context?(context.old_contextual_ast) || code?(context.old_contextual_ast.target_node))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# @return [String]
|
|
12
|
+
def string_representation
|
|
13
|
+
first_line = code_first_line(change_context.old_contextual_ast)
|
|
14
|
+
return "remove #{first_line} code sample" unless first_line.empty?
|
|
15
|
+
'remove code sample'
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module MetaCommit::Extension::MarkdownSupport::Diffs
|
|
2
|
+
class Diff < MetaCommit::Contracts::Diff
|
|
3
|
+
include MetaCommit::Extension::MarkdownSupport::ContextualAstAccessor
|
|
4
|
+
|
|
5
|
+
SUPPORTED_PARSERS = [MetaCommit::Extension::MarkdownSupport::Parsers::Markdown]
|
|
6
|
+
|
|
7
|
+
# @param [Class] parser
|
|
8
|
+
# @return [Boolean]
|
|
9
|
+
def supports_parser?(parser)
|
|
10
|
+
SUPPORTED_PARSERS.include?(parser)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# @param [MetaCommit::Contracts::ChangeContext] context
|
|
14
|
+
# @return [Boolean]
|
|
15
|
+
def supports_change(context)
|
|
16
|
+
# TODO Set to false
|
|
17
|
+
true
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# @return [String]
|
|
21
|
+
def inspect
|
|
22
|
+
string_representation
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# @return [String]
|
|
26
|
+
def to_s
|
|
27
|
+
string_representation
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# @return [String]
|
|
31
|
+
def string_representation
|
|
32
|
+
"perform #{change_context.type}"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# @return [Boolean]
|
|
36
|
+
def type_addition?
|
|
37
|
+
change_context.type == TYPE_ADDITION
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# @return [Boolean]
|
|
41
|
+
def type_deletion?
|
|
42
|
+
change_context.type == TYPE_DELETION
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# @return [Boolean]
|
|
46
|
+
def type_replace?
|
|
47
|
+
change_context.type == TYPE_REPLACE
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module MetaCommit::Extension::MarkdownSupport::Diffs
|
|
2
|
+
class ListAddition < Diff
|
|
3
|
+
# @param [MetaCommit::Contracts::ChangeContext] context
|
|
4
|
+
# @return [Boolean]
|
|
5
|
+
def supports_change(context)
|
|
6
|
+
context.type == TYPE_ADDITION &&
|
|
7
|
+
contextual_ast_has_target_node(context.old_contextual_ast) && contextual_ast_has_target_node(context.new_contextual_ast) &&
|
|
8
|
+
list_context?(context.new_contextual_ast)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# @return [String]
|
|
12
|
+
def string_representation
|
|
13
|
+
if nested_list_context?(change_context.new_contextual_ast)
|
|
14
|
+
parent_li_title = parent_list_item_title(change_context.new_contextual_ast)
|
|
15
|
+
return "add sublist to #{parent_li_title.strip}"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
header_content = closest_header_of_list(change_context.new_contextual_ast)
|
|
19
|
+
return "add list to #{header_content}" unless header_content.nil?
|
|
20
|
+
'add list'
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module MetaCommit::Extension::MarkdownSupport::Diffs
|
|
2
|
+
class ListChange < Diff
|
|
3
|
+
# @param [MetaCommit::Contracts::ChangeContext] context
|
|
4
|
+
# @return [Boolean]
|
|
5
|
+
def supports_change(context)
|
|
6
|
+
context.type == TYPE_REPLACE &&
|
|
7
|
+
contextual_ast_has_target_node(context.old_contextual_ast) &&
|
|
8
|
+
contextual_ast_has_target_node(context.new_contextual_ast) &&
|
|
9
|
+
list_context?(context.old_contextual_ast) &&
|
|
10
|
+
list_context?(context.new_contextual_ast)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# @return [String]
|
|
14
|
+
def string_representation
|
|
15
|
+
# item add to #{list_name()}
|
|
16
|
+
if nested_list_context?(change_context.new_contextual_ast)
|
|
17
|
+
parent_li_title = parent_list_item_title(change_context.new_contextual_ast)
|
|
18
|
+
return "add item to #{parent_li_title.strip} sublist"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
header_content = closest_header_of_list(change_context.new_contextual_ast)
|
|
22
|
+
return "add item to #{header_content} list" unless header_content.nil?
|
|
23
|
+
'add list'
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module MetaCommit::Extension::MarkdownSupport::Diffs
|
|
2
|
+
class ListDeletion < Diff
|
|
3
|
+
# @param [MetaCommit::Contracts::ChangeContext] context
|
|
4
|
+
# @return [Boolean]
|
|
5
|
+
def supports_change(context)
|
|
6
|
+
context.type == TYPE_DELETION &&
|
|
7
|
+
contextual_ast_has_target_node(context.old_contextual_ast) &&
|
|
8
|
+
list_context?(context.old_contextual_ast)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# @return [String]
|
|
12
|
+
def string_representation
|
|
13
|
+
if nested_list_context?(change_context.old_contextual_ast)
|
|
14
|
+
parent_li_title = parent_list_item_title(change_context.old_contextual_ast)
|
|
15
|
+
return "remove #{parent_li_title.strip} sublist"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
header_content = closest_header_of_list(change_context.old_contextual_ast)
|
|
19
|
+
return "remove #{header_content} list" unless header_content.nil?
|
|
20
|
+
'remove list'
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module MetaCommit::Extension::MarkdownSupport::Diffs
|
|
2
|
+
class TextAddition < Diff
|
|
3
|
+
# @param [MetaCommit::Contracts::ChangeContext] context
|
|
4
|
+
# @return [Boolean]
|
|
5
|
+
def supports_change(context)
|
|
6
|
+
context.type == TYPE_ADDITION &&
|
|
7
|
+
contextual_ast_has_target_node(context.new_contextual_ast) &&
|
|
8
|
+
text?(context.new_contextual_ast.target_node)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# @return [String]
|
|
12
|
+
def string_representation
|
|
13
|
+
# because target_node is [text]
|
|
14
|
+
# and [parent element] - has -> [paragraph] - has -> [text]
|
|
15
|
+
# and wee need to get access to [parent_element] neighbours
|
|
16
|
+
parent_element_depth = change_context.new_contextual_ast.context_nodes.count - 2
|
|
17
|
+
parent_element_neighbours = context_node_neighbours(change_context.new_contextual_ast, parent_element_depth)
|
|
18
|
+
if !(parent_element_neighbours.empty?) && header?(parent_element_neighbours.last)
|
|
19
|
+
header = header_content(parent_element_neighbours.last)
|
|
20
|
+
return "add text to '#{header}' section"
|
|
21
|
+
end
|
|
22
|
+
"add text to #{change_context.new_file_path}"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module MetaCommit::Extension::MarkdownSupport::Diffs
|
|
2
|
+
class TextChange < Diff
|
|
3
|
+
# @param [MetaCommit::Contracts::ChangeContext] context
|
|
4
|
+
# @return [Boolean]
|
|
5
|
+
def supports_change(context)
|
|
6
|
+
context.type == TYPE_REPLACE &&
|
|
7
|
+
contextual_ast_has_target_node(context.old_contextual_ast) &&
|
|
8
|
+
contextual_ast_has_target_node(context.new_contextual_ast) &&
|
|
9
|
+
text?(context.old_contextual_ast.target_node) &&
|
|
10
|
+
text?(context.new_contextual_ast.target_node)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# @return [String]
|
|
14
|
+
def string_representation
|
|
15
|
+
# because target_node is [text]
|
|
16
|
+
# and [parent element] - has -> [paragraph] - has -> [text]
|
|
17
|
+
# and we need to get access to [parent_element] neighbours
|
|
18
|
+
parent_element_depth = change_context.new_contextual_ast.context_nodes.count - 2
|
|
19
|
+
parent_element_neighbours = context_node_neighbours(change_context.new_contextual_ast, parent_element_depth)
|
|
20
|
+
if !parent_element_neighbours.last.nil? && header?(parent_element_neighbours.last)
|
|
21
|
+
header = header_content(parent_element_neighbours.last)
|
|
22
|
+
return "change content of #{header} section"
|
|
23
|
+
end
|
|
24
|
+
"change #{change_context.new_file_path}"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module MetaCommit::Extension::MarkdownSupport::Diffs
|
|
2
|
+
class TextDeletion < Diff
|
|
3
|
+
# @param [MetaCommit::Contracts::ChangeContext] context
|
|
4
|
+
# @return [Boolean]
|
|
5
|
+
def supports_change(context)
|
|
6
|
+
context.type == TYPE_DELETION &&
|
|
7
|
+
contextual_ast_has_target_node(context.old_contextual_ast) &&
|
|
8
|
+
text?(context.old_contextual_ast.target_node)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# @return [String]
|
|
12
|
+
def string_representation
|
|
13
|
+
# because target_node is [text]
|
|
14
|
+
# and [parent element] - has -> [paragraph] - has -> [text]
|
|
15
|
+
# and wee need to get access to [parent_element] neighbours
|
|
16
|
+
parent_element_depth = change_context.old_contextual_ast.context_nodes.count - 2
|
|
17
|
+
parent_element_neighbours = context_node_neighbours(change_context.old_contextual_ast, parent_element_depth)
|
|
18
|
+
if !(parent_element_neighbours.empty?) && header?(parent_element_neighbours.last)
|
|
19
|
+
header = header_content(parent_element_neighbours.last)
|
|
20
|
+
return "remove paragraph from '#{header}' section"
|
|
21
|
+
end
|
|
22
|
+
"remove paragraph from #{change_context.new_file_path}"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
module MetaCommit::Extension::MarkdownSupport
|
|
2
|
+
module ContextualAstAccessor
|
|
3
|
+
ELEMENT_TYPE_ANCHOR = :link
|
|
4
|
+
ELEMENT_TYPE_LISTS = :list
|
|
5
|
+
ELEMENT_TYPE_LIST_ITEM = :list_item
|
|
6
|
+
ELEMENT_TYPE_HEADER = :header
|
|
7
|
+
ELEMENT_TYPE_CODE = :code_block
|
|
8
|
+
ELEMENT_TYPE_TEXT = :text
|
|
9
|
+
ELEMENT_TYPE_PARAGRAPH = :paragraph
|
|
10
|
+
ELEMENT_TYPE_IMAGE = :image
|
|
11
|
+
|
|
12
|
+
# @param [MetaCommit::Model::ContextualAst] contextual_ast
|
|
13
|
+
# @param [Symbol] type
|
|
14
|
+
# @param [Numeric] line
|
|
15
|
+
# @return [Boolean, Nil]
|
|
16
|
+
def elements_of_type_on_line(contextual_ast, type, line)
|
|
17
|
+
context_nodes_on_line(contextual_ast, line)
|
|
18
|
+
.select {|node| node.element.type == type}
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# @param [Array<MetaCommit::Model::Ast>] nodes
|
|
22
|
+
# @param [Numeric] column
|
|
23
|
+
# @return [Boolean, Nil]
|
|
24
|
+
def element_closest_to(nodes, column)
|
|
25
|
+
nodes
|
|
26
|
+
.select {|node| column.nil? || node.first_column.nil? || node.last_column.nil? || node.first_column <= column}
|
|
27
|
+
.last
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# @param [MetaCommit::Model::ContextualAst] contextual_ast
|
|
31
|
+
# @return [Boolean]
|
|
32
|
+
def anchor_context?(contextual_ast)
|
|
33
|
+
contextual_ast.context_nodes.any? {|node| anchor?(node)}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @param [MetaCommit::Extension::MarkdownSupport::Models::Ast] ast
|
|
37
|
+
def anchor?(ast)
|
|
38
|
+
ast.element.type == ELEMENT_TYPE_ANCHOR
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# @param [MetaCommit::Model::ContextualAst] contextual_ast
|
|
42
|
+
# @return [String]
|
|
43
|
+
def anchor_title(contextual_ast)
|
|
44
|
+
anchor = contextual_ast.context_nodes.find {|node| anchor?(node)}
|
|
45
|
+
return anchor.element.first_child.first_child.string_content unless text?(anchor.children.first)
|
|
46
|
+
anchor.element.first_child.string_content
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# @param [MetaCommit::Model::ContextualAst] contextual_ast
|
|
50
|
+
# @return [String]
|
|
51
|
+
def anchor_target(contextual_ast)
|
|
52
|
+
anchor = contextual_ast.context_nodes.find {|node| anchor?(node)}
|
|
53
|
+
anchor.element.url
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# @param [MetaCommit::Model::ContextualAst] contextual_ast
|
|
57
|
+
# @return [Boolean]
|
|
58
|
+
def list_context?(contextual_ast)
|
|
59
|
+
contextual_ast.context_nodes.any? {|node| list?(node)}
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# @param [MetaCommit::Model::ContextualAst] contextual_ast
|
|
63
|
+
# @return [Boolean]
|
|
64
|
+
def nested_list_context?(contextual_ast)
|
|
65
|
+
contextual_ast.context_nodes.count {|node| list?(node)} > 1
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# @param [MetaCommit::Model::ContextualAst] contextual_ast
|
|
69
|
+
# @return [String]
|
|
70
|
+
def parent_list_item_title(contextual_ast)
|
|
71
|
+
parent_element = contextual_ast
|
|
72
|
+
.context_nodes.reverse # walk from closest node to border
|
|
73
|
+
.select {|node| list_item?(node)}[1] # li elements
|
|
74
|
+
.children.first.children.first
|
|
75
|
+
string_content(parent_element)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# @param [MetaCommit::Extension::MarkdownSupport::Models::Ast] ast
|
|
79
|
+
# @return [Boolean]
|
|
80
|
+
def list?(ast)
|
|
81
|
+
ast.element.type == ELEMENT_TYPE_LISTS
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# @param [MetaCommit::Extension::MarkdownSupport::Models::Ast] ast
|
|
85
|
+
# @return [Boolean]
|
|
86
|
+
def list_item?(ast)
|
|
87
|
+
ast.element.type == ELEMENT_TYPE_LIST_ITEM
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# @param [MetaCommit::Model::ContextualAst] contextual_ast
|
|
91
|
+
# @return [String]
|
|
92
|
+
def closest_header_of_list(contextual_ast)
|
|
93
|
+
sibling_neighbours = context_node_neighbours(contextual_ast)
|
|
94
|
+
|
|
95
|
+
closest_header = sibling_neighbours.reverse.find {|neighbour| header?(neighbour)}
|
|
96
|
+
closest_header.children.first.element.string_content unless closest_header.nil?
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# @param [MetaCommit::Model::ContextualAst] contextual_ast
|
|
100
|
+
# @return [String]
|
|
101
|
+
def code_context?(contextual_ast)
|
|
102
|
+
contextual_ast.context_nodes.any? {|node| code?(node)}
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# @param [MetaCommit::Extension::MarkdownSupport::Models::Ast] ast
|
|
106
|
+
# @return [Boolean]
|
|
107
|
+
def code?(ast)
|
|
108
|
+
ast.element.type == ELEMENT_TYPE_CODE
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# @param [MetaCommit::Model::ContextualAst] contextual_ast
|
|
112
|
+
# @return [String]
|
|
113
|
+
def code_first_line(contextual_ast)
|
|
114
|
+
codespan = contextual_ast.context_nodes.reverse.find {|node| code?(node)}
|
|
115
|
+
codespan.element.fence_info
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# @param [MetaCommit::Model::ContextualAst] contextual_ast
|
|
119
|
+
# @return [String]
|
|
120
|
+
def text_context?(contextual_ast)
|
|
121
|
+
contextual_ast.context_nodes.any? {|node| text?(node)}
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# @param [MetaCommit::Extension::MarkdownSupport::Models::Ast] ast
|
|
125
|
+
# @return [Boolean]
|
|
126
|
+
def text?(ast)
|
|
127
|
+
ast.element.type == ELEMENT_TYPE_TEXT
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# @param [MetaCommit::Model::ContextualAst] contextual_ast
|
|
131
|
+
# @return [String]
|
|
132
|
+
def paragraph_context?(contextual_ast)
|
|
133
|
+
contextual_ast.context_nodes.any? {|node| paragraph?(node)}
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# @param [MetaCommit::Extension::MarkdownSupport::Models::Ast] ast
|
|
137
|
+
# @return [Boolean]
|
|
138
|
+
def paragraph?(ast)
|
|
139
|
+
ast.element.type == ELEMENT_TYPE_PARAGRAPH
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# @param [MetaCommit::Extension::MarkdownSupport::Models::Ast] ast
|
|
143
|
+
# @return [Boolean]
|
|
144
|
+
def header?(ast)
|
|
145
|
+
ast.element.type == ELEMENT_TYPE_HEADER
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# @param [MetaCommit::Extension::MarkdownSupport::Models::Ast] ast
|
|
149
|
+
# @return [String]
|
|
150
|
+
def header_content(ast)
|
|
151
|
+
ast.children.first.element.string_content
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# returns ast node that goes before contextual_ast.target_node
|
|
155
|
+
# contextual_ast.context_nodes are filled using depth-first search
|
|
156
|
+
# this method returns value using breadth-first search
|
|
157
|
+
# @param [MetaCommit::Model::ContextualAst] contextual_ast
|
|
158
|
+
# @param [Numeric] depth of level where to search for previous ast
|
|
159
|
+
# @return [MetaCommit::Extension::MarkdownSupport::Model::Ast, nil (?)]
|
|
160
|
+
def context_node_neighbours(contextual_ast, depth=1)
|
|
161
|
+
# TODO depth can be root
|
|
162
|
+
target_node_sibling = contextual_ast.context_nodes[depth]
|
|
163
|
+
node_to_be_searched = contextual_ast.context_nodes[depth - 1]
|
|
164
|
+
previous_children = []
|
|
165
|
+
node_to_be_searched.children.map do |child|
|
|
166
|
+
break if child == target_node_sibling
|
|
167
|
+
previous_children << child
|
|
168
|
+
end
|
|
169
|
+
previous_children
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# @param [MetaCommit::Model::ContextualAst] ast
|
|
173
|
+
# @return [Boolean]
|
|
174
|
+
def contextual_ast_has_target_node(ast)
|
|
175
|
+
!ast.target_node.nil?
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
# @param [MetaCommit::Contracts::Ast] ast
|
|
179
|
+
# @param [Integer] line
|
|
180
|
+
# @return [Boolean]
|
|
181
|
+
def starts_on_line?(ast, line)
|
|
182
|
+
ast.first_line === line
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# @param [MetaCommit::Model::ContextualAst] contextual_ast
|
|
186
|
+
# @param [Numeric] line
|
|
187
|
+
# @return [Array<MetaCommit::Model::Node>]
|
|
188
|
+
def context_nodes_on_line(contextual_ast, line)
|
|
189
|
+
contextual_ast.context_nodes.select {|node| starts_on_line?(node, line)}
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
# @param [MetaCommit::Extension::MarkdownSupport::Models::Ast] ast
|
|
193
|
+
# @return [Boolean]
|
|
194
|
+
def image?(ast)
|
|
195
|
+
ast.element.type == ELEMENT_TYPE_IMAGE
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
# @param [Models::Ast] ast
|
|
199
|
+
# @return [String]
|
|
200
|
+
def string_content(ast)
|
|
201
|
+
case ast.element.type
|
|
202
|
+
when ELEMENT_TYPE_ANCHOR
|
|
203
|
+
ast.children.first.element.string_content
|
|
204
|
+
when ELEMENT_TYPE_LIST_ITEM
|
|
205
|
+
ast.children.first.children.first.element.string_content
|
|
206
|
+
else
|
|
207
|
+
ast.element.string_content
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module MetaCommit::Extension::MarkdownSupport
|
|
2
|
+
# Package interface
|
|
3
|
+
class Locator < MetaCommit::Contracts::Locator
|
|
4
|
+
# @return [Array] parser classes that package provides
|
|
5
|
+
def parsers
|
|
6
|
+
[
|
|
7
|
+
MetaCommit::Extension::MarkdownSupport::Parsers::Markdown
|
|
8
|
+
]
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# @return [Array] diff classes that package provides
|
|
12
|
+
def diffs
|
|
13
|
+
[
|
|
14
|
+
MetaCommit::Extension::MarkdownSupport::Diffs::AnchorAddition,
|
|
15
|
+
MetaCommit::Extension::MarkdownSupport::Diffs::AnchorDeletion,
|
|
16
|
+
MetaCommit::Extension::MarkdownSupport::Diffs::AnchorRename,
|
|
17
|
+
MetaCommit::Extension::MarkdownSupport::Diffs::CodeAddition,
|
|
18
|
+
MetaCommit::Extension::MarkdownSupport::Diffs::CodeChange,
|
|
19
|
+
MetaCommit::Extension::MarkdownSupport::Diffs::CodeDeletion,
|
|
20
|
+
MetaCommit::Extension::MarkdownSupport::Diffs::ListAddition,
|
|
21
|
+
MetaCommit::Extension::MarkdownSupport::Diffs::ListChange,
|
|
22
|
+
MetaCommit::Extension::MarkdownSupport::Diffs::ListDeletion,
|
|
23
|
+
MetaCommit::Extension::MarkdownSupport::Diffs::TextAddition,
|
|
24
|
+
MetaCommit::Extension::MarkdownSupport::Diffs::TextChange,
|
|
25
|
+
MetaCommit::Extension::MarkdownSupport::Diffs::TextDeletion
|
|
26
|
+
]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module MetaCommit::Extension::MarkdownSupport::Models
|
|
2
|
+
# Adapter which implements MetaCommit::Contracts::Ast contract and wraps CommonMarker::Node
|
|
3
|
+
# @attr [CommonMarker::Node] element
|
|
4
|
+
class Ast < MetaCommit::Contracts::Ast
|
|
5
|
+
attr_reader :element
|
|
6
|
+
|
|
7
|
+
# @param [CommonMarker::Node] element
|
|
8
|
+
def initialize(element)
|
|
9
|
+
@element = element
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# @return [Array<MetaCommit::Contracts::Ast>] children ast
|
|
13
|
+
def children
|
|
14
|
+
element.each.map do |child|
|
|
15
|
+
Ast.new(child)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# @return [Integer, nil] line number where ast starts
|
|
20
|
+
def first_line
|
|
21
|
+
element.sourcepos[:start_line]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# @return [Integer, nil] line number where ast ends
|
|
25
|
+
def last_line
|
|
26
|
+
element.sourcepos[:end_line]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# @return [Integer, nil] column number where ast starts
|
|
30
|
+
def first_column
|
|
31
|
+
return nil if element.sourcepos[:start_column].nil?
|
|
32
|
+
element.sourcepos[:start_column] - 1
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# @return [Integer, nil] column number where ast ends
|
|
36
|
+
def last_column
|
|
37
|
+
return nil if element.sourcepos[:end_column].nil?
|
|
38
|
+
element.sourcepos[:end_column] - 1
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# @param [MetaCommit::Extension::MarkdownSupport::Models::Ast] right_ast
|
|
42
|
+
# @return [Boolean]
|
|
43
|
+
def ==(right_ast)
|
|
44
|
+
element == right_ast.element
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'commonmarker'
|
|
2
|
+
|
|
3
|
+
module MetaCommit::Extension::MarkdownSupport::Parsers
|
|
4
|
+
class Markdown < MetaCommit::Contracts::Parser
|
|
5
|
+
# @return [Array<String>] supported extensions
|
|
6
|
+
def self.supported_file_extensions
|
|
7
|
+
%w(.markdown .mdown .mkdn .md .mkd .mdwn .mdtxt .mdtext .Rmd)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# @param [String] source_code
|
|
11
|
+
# @return [Boolean]
|
|
12
|
+
def self.supports_syntax?(source_code)
|
|
13
|
+
begin
|
|
14
|
+
document = CommonMarker.render_doc(source_code)
|
|
15
|
+
!document.nil?
|
|
16
|
+
rescue Encoding::UndefinedConversionError => e
|
|
17
|
+
return false
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# @param [String] source_code
|
|
22
|
+
# @return [MetaCommit::Contracts::Ast]
|
|
23
|
+
def parse(source_code)
|
|
24
|
+
document = CommonMarker.render_doc(source_code)
|
|
25
|
+
MetaCommit::Extension::MarkdownSupport::Models::Ast.new(document)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'redcarpet'
|
|
2
|
+
require 'byebug'
|
|
3
|
+
|
|
4
|
+
class CustomRender < Redcarpet::Render::HTML
|
|
5
|
+
def block_quote(quote)
|
|
6
|
+
byebug
|
|
7
|
+
%(<blockquote class="my-custom-class">#{quote}</blockquote>)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# class RendererNew < Redcarpet::Render::HTML
|
|
12
|
+
# def block_code(code, language)
|
|
13
|
+
# byebug
|
|
14
|
+
# "hgffgghfghfghfgfgfgfghghfgfhfghhgf"
|
|
15
|
+
# end
|
|
16
|
+
# end
|
|
17
|
+
|
|
18
|
+
# class RenderWithoutCode < Redcarpet::Render::HTML
|
|
19
|
+
# def block_code(code, language)
|
|
20
|
+
# nil
|
|
21
|
+
# end
|
|
22
|
+
# end
|
|
23
|
+
#
|
|
24
|
+
# block_code(code, language)
|
|
25
|
+
# block_quote(quote)
|
|
26
|
+
# block_html(raw_html)
|
|
27
|
+
# footnotes(content)
|
|
28
|
+
# footnote_def(content, number)
|
|
29
|
+
# header(text, header_level)
|
|
30
|
+
# hrule()
|
|
31
|
+
# list(contents, list_type)
|
|
32
|
+
# list_item(text, list_type)
|
|
33
|
+
# paragraph(text)
|
|
34
|
+
# table(header, body)
|
|
35
|
+
# table_row(content)
|
|
36
|
+
# table_cell(content, alignment)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "meta_commit_markdown_support/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "meta_commit_markdown_support"
|
|
8
|
+
spec.version = MetaCommit::Extension::MarkdownSupport::VERSION
|
|
9
|
+
spec.authors = ["Stanislav Dobrovolskiy"]
|
|
10
|
+
spec.email = ["uusername@protonmail.ch"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{meta_commit extension adds markdown language support}
|
|
13
|
+
spec.homepage = "https://github.com/meta-commit/markdown_support"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/})}
|
|
17
|
+
spec.bindir = "exe"
|
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_runtime_dependency "meta_commit_contracts", "~> 0"
|
|
22
|
+
spec.add_runtime_dependency "commonmarker", "~> 0.17"
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16.a"
|
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
27
|
+
spec.add_development_dependency "byebug"
|
|
28
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: meta_commit_markdown_support
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Stanislav Dobrovolskiy
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-02-28 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: meta_commit_contracts
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: commonmarker
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0.17'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0.17'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: bundler
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 1.16.a
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 1.16.a
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rake
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '10.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '10.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rspec
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '3.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '3.0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: byebug
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
description:
|
|
98
|
+
email:
|
|
99
|
+
- uusername@protonmail.ch
|
|
100
|
+
executables: []
|
|
101
|
+
extensions: []
|
|
102
|
+
extra_rdoc_files: []
|
|
103
|
+
files:
|
|
104
|
+
- ".gitignore"
|
|
105
|
+
- ".rspec"
|
|
106
|
+
- ".travis.yml"
|
|
107
|
+
- CODE_OF_CONDUCT.md
|
|
108
|
+
- Gemfile
|
|
109
|
+
- LICENSE.txt
|
|
110
|
+
- README.md
|
|
111
|
+
- Rakefile
|
|
112
|
+
- bin/console
|
|
113
|
+
- bin/setup
|
|
114
|
+
- lib/meta_commit_markdown_support.rb
|
|
115
|
+
- lib/meta_commit_markdown_support/diffs/anchor_addition.rb
|
|
116
|
+
- lib/meta_commit_markdown_support/diffs/anchor_deletion.rb
|
|
117
|
+
- lib/meta_commit_markdown_support/diffs/anchor_rename.rb
|
|
118
|
+
- lib/meta_commit_markdown_support/diffs/code_addition.rb
|
|
119
|
+
- lib/meta_commit_markdown_support/diffs/code_change.rb
|
|
120
|
+
- lib/meta_commit_markdown_support/diffs/code_deletion.rb
|
|
121
|
+
- lib/meta_commit_markdown_support/diffs/diff.rb
|
|
122
|
+
- lib/meta_commit_markdown_support/diffs/list_addition.rb
|
|
123
|
+
- lib/meta_commit_markdown_support/diffs/list_change.rb
|
|
124
|
+
- lib/meta_commit_markdown_support/diffs/list_deletion.rb
|
|
125
|
+
- lib/meta_commit_markdown_support/diffs/text_addition.rb
|
|
126
|
+
- lib/meta_commit_markdown_support/diffs/text_change.rb
|
|
127
|
+
- lib/meta_commit_markdown_support/diffs/text_deletion.rb
|
|
128
|
+
- lib/meta_commit_markdown_support/helpers/contextual_ast_accessor.rb
|
|
129
|
+
- lib/meta_commit_markdown_support/locator.rb
|
|
130
|
+
- lib/meta_commit_markdown_support/models/ast.rb
|
|
131
|
+
- lib/meta_commit_markdown_support/parsers/markdown.rb
|
|
132
|
+
- lib/meta_commit_markdown_support/renderer.rb
|
|
133
|
+
- lib/meta_commit_markdown_support/version.rb
|
|
134
|
+
- meta_commit_markdown_support.gemspec
|
|
135
|
+
homepage: https://github.com/meta-commit/markdown_support
|
|
136
|
+
licenses:
|
|
137
|
+
- MIT
|
|
138
|
+
metadata: {}
|
|
139
|
+
post_install_message:
|
|
140
|
+
rdoc_options: []
|
|
141
|
+
require_paths:
|
|
142
|
+
- lib
|
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
|
+
requirements:
|
|
145
|
+
- - ">="
|
|
146
|
+
- !ruby/object:Gem::Version
|
|
147
|
+
version: '0'
|
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
|
+
requirements:
|
|
150
|
+
- - ">="
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: '0'
|
|
153
|
+
requirements: []
|
|
154
|
+
rubyforge_project:
|
|
155
|
+
rubygems_version: 2.5.2
|
|
156
|
+
signing_key:
|
|
157
|
+
specification_version: 4
|
|
158
|
+
summary: meta_commit extension adds markdown language support
|
|
159
|
+
test_files: []
|