Skip to content

Commit

Permalink
Add support for dark mode.
Browse files Browse the repository at this point in the history
Also drop old rubies.

Closes #45
  • Loading branch information
patrickdavey committed Apr 2, 2023
1 parent 343ccde commit 3a00e6b
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 11 deletions.
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ before_install:
- gem install bundler -v '< 2'
language: ruby
rvm:
- 2.3.8
- 2.4.10
- 2.5.8
- 2.6.6
- 2.7.2
- 3.0.0
- 2.7.8
- 3.0.6
- 3.1.4
- 3.2.2
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ It is a requirement that your template file contain a placeholder
for the syntax highlighting code to be placed. In order to do this,
open up your default.tpl (or whatever your template file is called)
and ensure that before the closing </head> tag you put
`%pygments%`
`%pygments%`. You also have the option to put `%dark_pygments%` if you want to have "dark mode" syntax highlighting.

A sample tpl file is available here https://raw.githubusercontent.com/patrickdavey/vimwiki_markdown/master/example_files/default.tpl

Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.9.0 [02 April 2023]
Add support for dark mode. Drop support for ruby < 2.7

## 0.8.2 [22 June 2022]
Remove deprecation warning for EscapeUtils.escape_html
see https://github.com/patrickdavey/vimwiki_markdown/pull/43
Expand Down
15 changes: 13 additions & 2 deletions lib/vimwiki_markdown/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def fixtags(template)
end

def pygments_wrapped_in_tags
Rouge::Themes::Github.dark!
Rouge::Themes::Github.dark! if dark_template?

"<style type=\"text/css\">
#{::Rouge::Themes::Github.render(scope: '.highlight')}
</style>"
Expand All @@ -48,7 +49,17 @@ def title
end

def validate_template
raise MissingRequiredParamError.new("ERROR: vimwiki template must contain %pygments% placeholder token. Please visit https://github.com/patrickdavey/vimwiki_markdown for more information") unless @template =~ /%pygments%/
return if dark_template? || regular_template?

raise MissingRequiredParamError.new("ERROR: vimwiki template must contain %pygments% placeholder token. Please visit https://github.com/patrickdavey/vimwiki_markdown for more information")
end

def dark_template?
@template =~ /%dark_pygments%/
end

def regular_template?
@template =~ /%pygments%/
end
end
end
2 changes: 1 addition & 1 deletion lib/vimwiki_markdown/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module VimwikiMarkdown
VERSION = "0.8.2"
VERSION = "0.9.0"
end
12 changes: 12 additions & 0 deletions spec/lib/vimwiki_markdown/template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ module VimwikiMarkdown
end
end

context "dark pygments" do
before do
allow(Options).to receive(:arguments).and_return(Options::DEFAULTS)
end

it "should raise an invalid exception for missing pygments" do
allow(File).to receive(:open).with(options.template_filename, "r").and_return(StringIO.new(dark_pygments))
expect(Rouge::Themes::Github).to receive(:dark!) { true }
Template.new(options).to_s
end
end

context "using %root_path%" do
before do
allow(Options).to receive(:arguments).and_return(Options::DEFAULTS)
Expand Down
6 changes: 5 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,9 @@ def wiki_template
end

def template_missing_pygments
wiki_template.gsub!('%pygments%','')
wiki_template.gsub!("%pygments%", "")
end

def dark_pygments
wiki_template.gsub!("%pygments%", "%dark_pygments%")
end

0 comments on commit 3a00e6b

Please sign in to comment.