Sha256: c3c821af0bc2b7f8fe5f0ece4ed0783eb3e2fd27b56bdd49446b7704ad678dea
Contents?: true
Size: 1.59 KB
Versions: 38
Compression:
Stored size: 1.59 KB
Contents
# frozen_string_literal: true module Stepmod module Utils module Converters class Text < ReverseAdoc::Converters::Base def convert(node, state = {}) if node.text.strip.empty? treat_empty(node, state) else treat_text(node) end end private def treat_empty(node, state) parent = node.parent.name.to_sym if %i[ol ul].include?(parent) # Otherwise the identation is broken "" elsif state[:tdsinglepara] "" elsif node.text == " " # Regular whitespace text node " " else "" end end def treat_text(node) text = node.text text = preserve_nbsp(text) text = remove_inner_newlines(text) text = remove_border_newlines(text) text = preserve_keychars_within_backticks(text) preserve_tags(text) end def preserve_nbsp(text) text.gsub(/\u00A0/, " ") end def preserve_tags(text) text.gsub(/[<>]/, ">" => '\>', "<" => '\<') end def remove_border_newlines(text) text.gsub(/\A\n+/, "").gsub(/\n+\z/, "") end def remove_inner_newlines(text) text.tr("\n\t", " ").squeeze(" ") end def preserve_keychars_within_backticks(text) text.gsub(/`.*?`/) do |match| match.gsub('\_', "_").gsub('\*', "*") end end end ReverseAdoc::Converters.register :text, Text.new end end end
Version data entries
38 entries across 38 versions & 1 rubygems