rails-assets-markdown-it-lygneo-mention 0.2.1
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/Gemfile +4 -0
- data/Gemfile.lock +18 -0
- data/README.md +22 -0
- data/Rakefile +1 -0
- data/app/.DS_Store +0 -0
- data/app/assets/.DS_Store +0 -0
- data/app/assets/javascripts/.DS_Store +0 -0
- data/app/assets/javascripts/markdown-it-lygneo-mention.js +1 -0
- data/app/assets/javascripts/markdown-it-lygneo-mention/markdown-it-lygneo-mention.js +189 -0
- data/lib/rails-assets-markdown-it-lygneo-mention.rb +46 -0
- data/lib/rails-assets-markdown-it-lygneo-mention/version.rb +3 -0
- data/pkg/.DS_Store +0 -0
- data/pkg/rails-assets-markdown-it-lygneo-mention-0.2.1.gem +0 -0
- data/rails-assets-markdown-it-lygneo-mention.gemspec +20 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f5a67ecd47f8b251c0b6f978ad8157c77eb42bbb
|
4
|
+
data.tar.gz: a3643d466c5b6173bbb45c9db36e04476a7eef07
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0cf0e649e3a0511ad5be6617a30cfd5c61ad9fb0a80915185e97585b4293aab36db560c4a97d6c606b5c37f091bec476eb331d9a30eca874f4e779f21b89adfd
|
7
|
+
data.tar.gz: 0897ed20d1a7d0ece7dc0854da0c7bbca76ef9809b124c9f18765993359fff306e73cbbd5626870a0d30d7f0f35f187a131e0e1d27202aac9fbf44cfc948a106
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rails-assets-markdown-it-lygneo-mention (0.2.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
remote: https://rails-assets.org/
|
9
|
+
specs:
|
10
|
+
rake (10.4.2)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
bundler (~> 1.3)
|
17
|
+
rails-assets-markdown-it-lygneo-mention!
|
18
|
+
rake
|
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# rails-assets-markdown-it-lygneo-mention
|
2
|
+
|
3
|
+
> The Bower package inside a gem
|
4
|
+
|
5
|
+
This gem was automatically generated. You can visit [rails-assets.org](https://rails-assets.org) for more information.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
Add rails-assets source block to your `Gemfile`:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
source "https://rails-assets.org" do
|
13
|
+
gem "rails-assets-markdown-it-lygneo-mention"
|
14
|
+
end
|
15
|
+
|
16
|
+
```
|
17
|
+
|
18
|
+
Then, import the asset using Sprockets’ `require` directive:
|
19
|
+
|
20
|
+
```js
|
21
|
+
//= require "markdown-it-lygneo-mention"
|
22
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/app/.DS_Store
ADDED
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require markdown-it-lygneo-mention/markdown-it-lygneo-mention.js
|
@@ -0,0 +1,189 @@
|
|
1
|
+
/*! markdown-it-lygneo-mention 0.2.1 https://github.com/lygneo/markdown-it-lygneo-mention @license MIT */!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.markdownitLygneoMention=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
2
|
+
// Process @mention
|
3
|
+
|
4
|
+
'use strict';
|
5
|
+
|
6
|
+
//////////////////////////////////////////////////////////////////////////
|
7
|
+
// Renderer partials
|
8
|
+
|
9
|
+
function mention_open(tokens, idx) {
|
10
|
+
return '<a href="' +
|
11
|
+
tokens[idx].content +
|
12
|
+
'" class="' +
|
13
|
+
tokens[idx].linkclass +
|
14
|
+
'">';
|
15
|
+
}
|
16
|
+
|
17
|
+
function mention_close() { return '</a>'; }
|
18
|
+
|
19
|
+
function mention_text(tokens, idx) {
|
20
|
+
return tokens[idx].content;
|
21
|
+
}
|
22
|
+
|
23
|
+
//////////////////////////////////////////////////////////////////////////
|
24
|
+
|
25
|
+
function isLinkOpen(str) { return /^<a[>\s]/i.test(str); }
|
26
|
+
function isLinkClose(str) { return /^<\/a\s*>/i.test(str); }
|
27
|
+
|
28
|
+
module.exports = function mention_plugin(md, options) {
|
29
|
+
|
30
|
+
var arrayReplaceAt = md.utils.arrayReplaceAt;
|
31
|
+
var escapeHtml = md.utils.escapeHtml;
|
32
|
+
var mentions = [];
|
33
|
+
var currentUserId;
|
34
|
+
var allowHovercards;
|
35
|
+
|
36
|
+
if (typeof options.mentions !== 'undefined') {
|
37
|
+
mentions = options.mentions;
|
38
|
+
}
|
39
|
+
|
40
|
+
if (typeof options.currentUserId !== 'undefined') {
|
41
|
+
currentUserId = options.currentUserId;
|
42
|
+
}
|
43
|
+
|
44
|
+
if (typeof options.allowHovercards !== 'undefined') {
|
45
|
+
allowHovercards = options.allowHovercards;
|
46
|
+
}
|
47
|
+
|
48
|
+
function findPersonById(id) {
|
49
|
+
var i;
|
50
|
+
for (i = 0; i < mentions.length; i++) {
|
51
|
+
if (id === mentions[i].lygneo_id || id === mentions[i].handle) {
|
52
|
+
return mentions[i];
|
53
|
+
}
|
54
|
+
}
|
55
|
+
return null;
|
56
|
+
}
|
57
|
+
|
58
|
+
function mention(state) {
|
59
|
+
var i, j, l, m,
|
60
|
+
token,
|
61
|
+
tokens,
|
62
|
+
blockTokens = state.tokens,
|
63
|
+
htmlLinkLevel,
|
64
|
+
matches,
|
65
|
+
match,
|
66
|
+
pos,
|
67
|
+
name,
|
68
|
+
lygneoId,
|
69
|
+
person,
|
70
|
+
linkclass,
|
71
|
+
text,
|
72
|
+
nodes,
|
73
|
+
level,
|
74
|
+
regex,
|
75
|
+
regexGlobal,
|
76
|
+
mentionRegExp = '@\\{([^;]+); ([^\\}]+)\\}';
|
77
|
+
|
78
|
+
regex = new RegExp(mentionRegExp);
|
79
|
+
regexGlobal = new RegExp(mentionRegExp, 'g');
|
80
|
+
|
81
|
+
for (j = 0, l = blockTokens.length; j < l; j++) {
|
82
|
+
if (blockTokens[j].type !== 'inline') { continue; }
|
83
|
+
tokens = blockTokens[j].children;
|
84
|
+
htmlLinkLevel = 0;
|
85
|
+
|
86
|
+
for (i = tokens.length - 1; i >= 0; i--) {
|
87
|
+
token = tokens[i];
|
88
|
+
|
89
|
+
// skip content of markdown links
|
90
|
+
if (token.type === 'link_close') {
|
91
|
+
i--;
|
92
|
+
while (tokens[i].level !== token.level && tokens[i].type !== 'link_open') {
|
93
|
+
i--;
|
94
|
+
}
|
95
|
+
continue;
|
96
|
+
}
|
97
|
+
|
98
|
+
// skip content of html links
|
99
|
+
if (token.type === 'html_inline') {
|
100
|
+
// we are going backwards, so isLinkOpen shows end of link
|
101
|
+
if (isLinkOpen(token.content) && htmlLinkLevel > 0) {
|
102
|
+
htmlLinkLevel--;
|
103
|
+
}
|
104
|
+
if (isLinkClose(token.content)) {
|
105
|
+
htmlLinkLevel++;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
if (htmlLinkLevel > 0) { continue; }
|
109
|
+
|
110
|
+
if (token.type !== 'text') { continue; }
|
111
|
+
|
112
|
+
// find mentions
|
113
|
+
text = token.content;
|
114
|
+
matches = text.match(regexGlobal);
|
115
|
+
if (matches === null) { continue; }
|
116
|
+
nodes = [];
|
117
|
+
level = token.level;
|
118
|
+
|
119
|
+
for (m = 0; m < matches.length; m++) {
|
120
|
+
match = matches[m].match(regex);
|
121
|
+
pos = text.indexOf(matches[m]);
|
122
|
+
name = match[1];
|
123
|
+
lygneoId = match[2];
|
124
|
+
linkclass = 'mention';
|
125
|
+
|
126
|
+
if (pos > 0) {
|
127
|
+
nodes.push({
|
128
|
+
type: 'text',
|
129
|
+
content: text.slice(0, pos),
|
130
|
+
level: level
|
131
|
+
});
|
132
|
+
}
|
133
|
+
|
134
|
+
|
135
|
+
person = findPersonById(lygneoId);
|
136
|
+
|
137
|
+
if (person) {
|
138
|
+
if (allowHovercards && person.guid !== currentUserId) {
|
139
|
+
linkclass += ' hovercardable';
|
140
|
+
}
|
141
|
+
nodes.push({
|
142
|
+
type: 'mention_open',
|
143
|
+
content: person.url || '/people/' + person.guid,
|
144
|
+
linkclass: linkclass,
|
145
|
+
level: level++
|
146
|
+
});
|
147
|
+
nodes.push({
|
148
|
+
type: 'mention_text',
|
149
|
+
content: escapeHtml(name).trim(),
|
150
|
+
level: level
|
151
|
+
});
|
152
|
+
nodes.push({
|
153
|
+
type: 'mention_close',
|
154
|
+
content: lygneoId,
|
155
|
+
level: --level
|
156
|
+
});
|
157
|
+
} else {
|
158
|
+
nodes.push({
|
159
|
+
type: 'text',
|
160
|
+
content: name,
|
161
|
+
level: level
|
162
|
+
});
|
163
|
+
}
|
164
|
+
text = text.slice(pos + match[0].length);
|
165
|
+
}
|
166
|
+
|
167
|
+
if (text.length > 0) {
|
168
|
+
nodes.push({
|
169
|
+
type: 'text',
|
170
|
+
content: text,
|
171
|
+
level: state.level
|
172
|
+
});
|
173
|
+
}
|
174
|
+
|
175
|
+
// replace current node
|
176
|
+
tokens = arrayReplaceAt(tokens, i, nodes);
|
177
|
+
blockTokens[j].children = tokens;
|
178
|
+
}
|
179
|
+
}
|
180
|
+
}
|
181
|
+
|
182
|
+
md.core.ruler.after('inline', 'mention', mention);
|
183
|
+
md.renderer.rules.mention_open = mention_open;
|
184
|
+
md.renderer.rules.mention_text = mention_text;
|
185
|
+
md.renderer.rules.mention_close = mention_close;
|
186
|
+
};
|
187
|
+
|
188
|
+
},{}]},{},[1])(1)
|
189
|
+
});
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "rails-assets-markdown-it-lygneo-mention/version"
|
2
|
+
|
3
|
+
|
4
|
+
module RailsAssetsMarkdownItLygneoMention
|
5
|
+
|
6
|
+
def self.gem_path
|
7
|
+
Pathname(File.realpath(__FILE__)).join('../..')
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.gem_spec
|
11
|
+
Gem::Specification::load(
|
12
|
+
gem_path.join("rails-assets-markdown-it-lygneo-mention.gemspec").to_s
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.load_paths
|
17
|
+
gem_path.join('app/assets').each_child.to_a
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.dependencies
|
21
|
+
[
|
22
|
+
|
23
|
+
]
|
24
|
+
end
|
25
|
+
|
26
|
+
if defined?(Rails)
|
27
|
+
class Engine < ::Rails::Engine
|
28
|
+
# Rails -> use app/assets directory.
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
class RailsAssets
|
35
|
+
@components ||= []
|
36
|
+
|
37
|
+
class << self
|
38
|
+
attr_accessor :components
|
39
|
+
|
40
|
+
def load_paths
|
41
|
+
components.flat_map(&:load_paths)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
RailsAssets.components << RailsAssetsMarkdownItLygneoMention
|
data/pkg/.DS_Store
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rails-assets-markdown-it-lygneo-mention/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rails-assets-markdown-it-lygneo-mention"
|
8
|
+
spec.version = RailsAssetsMarkdownItLygneoMention::VERSION
|
9
|
+
spec.authors = ["rails-assets.org"]
|
10
|
+
spec.description = "lygneo mentions for markdown-it markdown parser"
|
11
|
+
spec.summary = "lygneo mentions for markdown-it markdown parser"
|
12
|
+
spec.homepage = "https://github.com/gumpyyyy/rails-assets-markdown-it-lygneo-mention-0"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `find ./* -type f | cut -b 3-`.split($/)
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
19
|
+
spec.add_development_dependency "rake"
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-assets-markdown-it-lygneo-mention
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- rails-assets.org
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: lygneo mentions for markdown-it markdown parser
|
42
|
+
email:
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- Gemfile
|
48
|
+
- Gemfile.lock
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- app/.DS_Store
|
52
|
+
- app/assets/.DS_Store
|
53
|
+
- app/assets/javascripts/.DS_Store
|
54
|
+
- app/assets/javascripts/markdown-it-lygneo-mention.js
|
55
|
+
- app/assets/javascripts/markdown-it-lygneo-mention/markdown-it-lygneo-mention.js
|
56
|
+
- lib/rails-assets-markdown-it-lygneo-mention.rb
|
57
|
+
- lib/rails-assets-markdown-it-lygneo-mention/version.rb
|
58
|
+
- pkg/.DS_Store
|
59
|
+
- pkg/rails-assets-markdown-it-lygneo-mention-0.2.1.gem
|
60
|
+
- rails-assets-markdown-it-lygneo-mention.gemspec
|
61
|
+
homepage: https://github.com/gumpyyyy/rails-assets-markdown-it-lygneo-mention-0
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.4.6
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: lygneo mentions for markdown-it markdown parser
|
85
|
+
test_files: []
|