From 4bdbbcd25a303795d6707201d016638ff6083269 Mon Sep 17 00:00:00 2001
From: Tim Lim
Date: Sun, 22 Oct 2023 22:08:51 +0800
Subject: [PATCH] CPP Fix - prevent source code parent replacement if parent is
a list item
---
lib/docs/filters/cppref/clean_html.rb | 2 +-
lib/docs/filters/cppref/fix_code.rb | 10 ++++++----
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/lib/docs/filters/cppref/clean_html.rb b/lib/docs/filters/cppref/clean_html.rb
index d7f564ff..d68e4f0b 100644
--- a/lib/docs/filters/cppref/clean_html.rb
+++ b/lib/docs/filters/cppref/clean_html.rb
@@ -57,7 +57,7 @@ module Docs
node.content = ' ' if node.content.empty?
end
- css('tt', 'span > span.source-cpp', 'span.t-c', 'span.t-lc', 'span.t-dsc-see-tt').each do |node|
+ css('tt', 'span > span.source-cpp', 'span.t-c', 'span.t-lc', 'span.t-dsc-see-tt', 'div.t-li1 > span.source-cpp', 'div.t-li2 > span.source-cpp', 'div.t-li3 > span.source-cpp').each do |node|
node.name = 'code'
node.remove_attribute('class')
node.content = node.content unless node.at_css('a')
diff --git a/lib/docs/filters/cppref/fix_code.rb b/lib/docs/filters/cppref/fix_code.rb
index c80a7426..e546640d 100644
--- a/lib/docs/filters/cppref/fix_code.rb
+++ b/lib/docs/filters/cppref/fix_code.rb
@@ -3,10 +3,12 @@ module Docs
class FixCodeFilter < Filter
def call
css('div > span.source-c', 'div > span.source-cpp').each do |node|
- node.inner_html = node.inner_html.gsub(/
\n?/, "\n").gsub("\n
\n", "\n")
- node.parent.name = 'pre'
- node.parent['class'] = node['class']
- node.parent.content = node.content
+ if (node.parent.classes||[]).none?{|className| ['t-li1','t-li2','t-li3'].include?(className) }
+ node.inner_html = node.inner_html.gsub(/
\n?/, "\n").gsub("\n\n", "\n")
+ node.parent.name = 'pre'
+ node.parent['class'] = node['class']
+ node.parent.content = node.content
+ end
end
nbsp = Nokogiri::HTML(' ').text