diff --git a/.gitignore b/.gitignore index f1a04f0..9ba0e4c 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ *.dlog *.bak *.opf +.DS_Store book/book.out .vscode/ book/bookch* diff --git a/website/Gemfile.lock b/website/Gemfile.lock index 527e36e..3816671 100644 --- a/website/Gemfile.lock +++ b/website/Gemfile.lock @@ -5,6 +5,8 @@ GEM method_source (1.0.0) nokogiri (1.15.3-arm64-darwin) racc (~> 1.4) + nokogiri (1.15.3-x86_64-darwin) + racc (~> 1.4) nokogiri (1.15.3-x86_64-linux) racc (~> 1.4) pry (0.14.2) @@ -14,6 +16,7 @@ GEM PLATFORMS arm64-darwin-22 + x86_64-darwin-22 x86_64-linux DEPENDENCIES diff --git a/website/modify_build.rb b/website/modify_build.rb index bedfd5e..f212d66 100644 --- a/website/modify_build.rb +++ b/website/modify_build.rb @@ -65,6 +65,7 @@ class ModifyBuild text = fix_list_of_tables_figures_duplicates(text) text = add_anchors_to_headers(text) text = fix_https_links(text) + text = add_anchors_to_glossary_items(text) if is_glossary_page?(filename) text = fix_menus_list_figures_tables(text) if is_list_figures_tables?(filename) text = fix_list_of_figures_tables_display(text) if is_list_figures_tables?(filename) File.open(filename, "w:UTF-8") {|file| file.puts text } @@ -76,6 +77,10 @@ class ModifyBuild end end + def is_glossary_page?(filename) + filename.include?("Glossary.html") + end + def is_list_figures_tables?(filename) ["listfigurename.html", "listtablename.html", "listoflocname.html", "bibname.html"].any? do |name| filename.include?(name) @@ -499,6 +504,23 @@ class ModifyBuild doc.to_html end + def add_anchors_to_glossary_items(text) + doc = build_doc(text) + content = doc.css("dt.description") + content.each do |el| + term = el.css("span")[0] + item_name = term&.text + # No anchor for whatever reason + next unless item_name + + anchor = item_name.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '') + copy_link = %Q{} + el.set_attribute("id", "term-#{anchor}") + term.inner_html = "#{term.inner_html}#{copy_link}" + end + doc.to_html + end + def build_cover_page_content %Q{