From 8e2e150be11df55e0571491cb670775c65001c6d Mon Sep 17 00:00:00 2001 From: japborst Date: Sun, 2 Oct 2016 17:58:09 +0200 Subject: [PATCH] iPython+notebook syntax highlighting and allowing data:image uris --- lib/docs/filters/core/normalize_urls.rb | 1 + lib/docs/filters/sphinx/clean_html.rb | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/docs/filters/core/normalize_urls.rb b/lib/docs/filters/core/normalize_urls.rb index 34b1ddeb..435eced2 100644 --- a/lib/docs/filters/core/normalize_urls.rb +++ b/lib/docs/filters/core/normalize_urls.rb @@ -11,6 +11,7 @@ module Docs def update_attribute(tag, attribute) css(tag.to_s).each do |node| + next if node[attribute].start_with?('data:image') next unless value = node[attribute] next if fragment_url_string?(value) node[attribute] = normalize_url(value) diff --git a/lib/docs/filters/sphinx/clean_html.rb b/lib/docs/filters/sphinx/clean_html.rb index 6dbd9dd3..323e1b7c 100644 --- a/lib/docs/filters/sphinx/clean_html.rb +++ b/lib/docs/filters/sphinx/clean_html.rb @@ -20,10 +20,18 @@ module Docs css('div[class*="highlight-"]').each do |node| pre = node.at_css('pre') pre.content = pre.content - pre['data-language'] = node['class'][/highlight\-(\w+)/, 1] - pre['data-language'] = 'php' if pre['data-language'] == 'ci' - pre['data-language'] = 'markup' if pre['data-language'] == 'html+django' - pre['data-language'] = 'python' if pre['data-language'] == 'default' || pre['data-language'].start_with?('python') + lang = node['class'][/highlight\-(\w+)/, 1] + lang = 'php' if lang == 'ci' + lang = 'markup' if lang == 'html+django' + lang = 'python' if lang == 'default' || lang.start_with?('python') || lang.start_with?('ipython') + pre['data-language'] = lang + node.replace(pre) + end + + # Support code blocks in jupyter notebook files + css('.code_cell div.highlight').each do |node| + pre = node.at_css('pre') + pre['data-language'] = 'python' node.replace(pre) end