-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from publify/move-text-filter-classes
Move text filter classes together into the PublifyCore::TextFilter namespace
- Loading branch information
Showing
20 changed files
with
170 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
require "text_filter_plugin" | ||
require "commonmarker" | ||
|
||
module PublifyCore::TextFilter | ||
class Markdown < TextFilterPlugin::Markup | ||
plugin_display_name "Markdown" | ||
plugin_description "Markdown markup language from" \ | ||
' <a href="http://daringfireball.com/">Daring Fireball</a>' | ||
|
||
def self.help_text | ||
<<~TXT | ||
[Markdown](http://daringfireball.net/projects/markdown/) is a simple | ||
text-to-HTML converter that turns common text idioms into HTML. The | ||
[full syntax](http://daringfireball.net/projects/markdown/syntax) is | ||
available from the author's site, but here's a short summary: | ||
* **Paragraphs**: Start a new paragraph by skipping a line. | ||
* **Italics**: Put text in *italics* by enclosing it in either * or | ||
_: `*italics*` turns into *italics*. | ||
* **Bold**: Put text in **bold** by enclosing it in two *s: | ||
`**bold**` turns into **bold**. | ||
* **Pre-formatted text**: Enclosing a short block of text in | ||
backquotes (`) displays it in a monospaced font and converts HTML | ||
metacharacters so they display correctly. Example: | ||
``<img src="foo"/>`` displays as `<img src="foo"/>`. Also, | ||
any paragraph indented 4 or more spaces is treated as pre-formatted | ||
text. | ||
* **Block quotes**: Any paragraph (or line) that starts with a `>` is | ||
treated as a blockquote. | ||
* **Hyperlinks**: You can create links like this: | ||
`[amazon's web site](http://www.amazon.com)`. That produces | ||
"[amazon's web site](http://www.amazon.com)". | ||
* **Lists**: You can create numbered or bulleted lists by ending a | ||
paragraph with a colon (:), skipping a line, and then using asterisks | ||
(*, for bullets) or numbers (for numbered lists). See the | ||
[Markdown syntax page](http://daringfireball.net/projects/markdown/syntax) | ||
for examples. | ||
* **Raw HTML**: Markdown will pass raw HTML through unchanged, so you | ||
can use HTML's syntax whenever Markdown doesn't provide a reasonable | ||
alternative. | ||
TXT | ||
end | ||
|
||
def self.filtertext(text) | ||
# FIXME: Workaround for <publify:foo> not being interpreted as an HTML tag. | ||
escaped_macros = text.gsub(%r{(</?publify):}, '\1X') | ||
html = CommonMarker.render_html(escaped_macros, :UNSAFE) | ||
html.gsub(%r{(</?publify)X}, '\1:').strip | ||
end | ||
end | ||
end |
6 changes: 3 additions & 3 deletions
6
...ublify_textfilter_markdown_smartquotes.rb → ..._core/text_filter/markdown_smartquotes.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
require "text_filter_plugin" | ||
|
||
module PublifyCore::TextFilter | ||
class None < TextFilterPlugin::Markup | ||
plugin_display_name "None" | ||
plugin_description "Raw HTML only" | ||
|
||
def self.filtertext(text) | ||
text | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rubypants" | ||
|
||
module PublifyCore::TextFilter | ||
class Smartypants < TextFilterPlugin::PostProcess | ||
plugin_display_name "Smartypants" | ||
plugin_description "Converts HTML to use typographically correct quotes and dashes" | ||
|
||
def self.filtertext(text) | ||
RubyPants.new(text).to_html | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
require "text_filter_plugin" | ||
require "html/pipeline" | ||
require "html/pipeline/hashtag/hashtag_filter" | ||
|
||
module PublifyCore::TextFilter | ||
class Twitterfilter < TextFilterPlugin::PostProcess | ||
plugin_display_name "HTML Filter" | ||
plugin_description "Strip HTML tags" | ||
|
||
class TwitterHashtagFilter < HTML::Pipeline::HashtagFilter | ||
def initialize(text) | ||
super(text, | ||
tag_url: "https://twitter.com/search?q=%%23%<tag>s&src=tren&mode=realtime", | ||
tag_link_attr: "") | ||
end | ||
end | ||
|
||
class TwitterMentionFilter < HTML::Pipeline::MentionFilter | ||
def initialize(text) | ||
super(text, base_url: "https://twitter.com") | ||
end | ||
|
||
# Override base mentions finder, treating @mention just like any other @foo. | ||
def self.mentioned_logins_in(text, username_pattern = UsernamePattern) | ||
text.gsub MentionPatterns[username_pattern] do |match| | ||
login = Regexp.last_match(1) | ||
yield match, login, false | ||
end | ||
end | ||
|
||
# Override base link creator, removing the class | ||
def link_to_mentioned_user(login) | ||
result[:mentioned_usernames] |= [login] | ||
|
||
url = base_url.dup | ||
url << "/" unless %r{[/~]\z}.match?(url) | ||
|
||
"<a href='#{url << login}'>" \ | ||
"@#{login}" \ | ||
"</a>" | ||
end | ||
end | ||
|
||
def self.filtertext(text) | ||
# First, autolink | ||
helper = PublifyCore::ContentTextHelpers.new | ||
text = helper.auto_link(text) | ||
|
||
text = TwitterHashtagFilter.new(text).call | ||
TwitterMentionFilter.new(text).call.to_s | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.