Cleanup tailwind classes when generating markup

pull/1711/head
IgnusG 3 years ago
parent 268441f33b
commit 7efdd2dbf0

@ -1,3 +1,26 @@
# Removes all classes not allowlisted in the below semantic_classes array - such as tailwinds utility classes
def cleanup_tailwind_classes(node)
class_name = node.attr("class")
if class_name == nil
return node.children.each { |child| cleanup_tailwind_classes(child) }
end
semantic_classes = ["code", "color-swatch", "color-swatch-container", "color-tone-information", "color-swatch-group", "color", "colors", "long-quick-reference"]
classes = class_name.split.select do |klas|
semantic_classes.include? klas
end
if classes.length === 0
node.delete("class")
else
node.set_attribute("class", classes.join(" "))
end
node.children.each { |child| cleanup_tailwind_classes(child) }
end
module Docs module Docs
class Tailwindcss class Tailwindcss
class CleanHtmlFilter < Filter class CleanHtmlFilter < Filter
@ -52,11 +75,12 @@ module Docs
node.parent.parent['class'] = node.parent.parent['class'].gsub(/bg-.*?\b/, ' '); node.parent.parent['class'] = node.parent.parent['class'].gsub(/bg-.*?\b/, ' ');
end end
@doc.traverse { |node| cleanup_tailwind_classes(node) }
#remove weird <hr> (https://github.com/damms005/devdocs/commit/8c9fbd859b71a2525b94a35ea994393ce2b6fedb#commitcomment-50091018) #remove weird <hr> (https://github.com/damms005/devdocs/commit/8c9fbd859b71a2525b94a35ea994393ce2b6fedb#commitcomment-50091018)
css('hr').remove css('hr').remove
doc doc
end end
end end
end end

Loading…
Cancel
Save