From dad4695a4abed50adbad09f6866f4b2bbd5c6568 Mon Sep 17 00:00:00 2001
From: John Fairhurst
Date: Fri, 1 Oct 2021 12:34:59 +0100
Subject: [PATCH] HTML fixes (#1281)
* Misplaced `rel=noopener`, missing alt-text, stray ``
* Malformed footnote lists
* Malformed math blocks
* Badly formed search bar
* Malformed section headers
---
CHANGELOG.md | 4 +++-
lib/jazzy/doc_builder.rb | 7 ++++++-
lib/jazzy/jazzy_markdown.rb | 16 +++++++++++++---
lib/jazzy/themes/apple/templates/doc.mustache | 3 +--
lib/jazzy/themes/apple/templates/footer.mustache | 2 +-
lib/jazzy/themes/apple/templates/header.mustache | 8 ++++----
.../themes/fullwidth/templates/doc.mustache | 3 +--
.../themes/fullwidth/templates/footer.mustache | 2 +-
.../themes/fullwidth/templates/header.mustache | 8 ++++----
lib/jazzy/themes/jony/templates/doc.mustache | 3 +--
lib/jazzy/themes/jony/templates/footer.mustache | 2 +-
lib/jazzy/themes/jony/templates/header.mustache | 4 ++--
spec/integration_specs | 2 +-
13 files changed, 39 insertions(+), 25 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 036ffb475..3a277ef38 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,7 +23,9 @@
##### Bug Fixes
-* None.
+* Improve HTML5 correctness, all themes.
+ [John Fairhurst](https://github.com/johnfairh)
+ [#1280](https://github.com/realm/jazzy/issues/1280)
## 0.14.0
diff --git a/lib/jazzy/doc_builder.rb b/lib/jazzy/doc_builder.rb
index 8de6a5d8d..88aef44b4 100644
--- a/lib/jazzy/doc_builder.rb
+++ b/lib/jazzy/doc_builder.rb
@@ -236,6 +236,11 @@ def self.render(doc_model, markdown)
SourceKitten.autolink_document(html, doc_model)
end
+ def self.render_inline(doc_model, markdown)
+ html = Markdown.render_inline(markdown)
+ SourceKitten.autolink_document(html, doc_model)
+ end
+
# Build Mustache document - common fields between page types
def self.new_document(source_module, doc_model)
Doc.new.tap do |doc|
@@ -379,7 +384,7 @@ def self.render_item(item, source_module)
def self.make_task(mark, uid, items, doc_model)
{
name: mark.name,
- name_html: (render(doc_model, mark.name) if mark.name),
+ name_html: (render_inline(doc_model, mark.name) if mark.name),
uid: ERB::Util.url_encode(uid),
items: items,
pre_separator: mark.has_start_dash,
diff --git a/lib/jazzy/jazzy_markdown.rb b/lib/jazzy/jazzy_markdown.rb
index d31346f06..136300b37 100644
--- a/lib/jazzy/jazzy_markdown.rb
+++ b/lib/jazzy/jazzy_markdown.rb
@@ -40,7 +40,8 @@ def footnote_def(text, num)
mapped = map_footnote(num)
"\n")
+ " ↩") +
+ ''
end
end
@@ -66,7 +67,9 @@ def header(text, header_level)
def codespan(text)
case text
when /^\$\$(.*)\$\$$/m
- o = ["", Regexp.last_match[1], '
']
+ o = ["
",
+ Regexp.last_match[1],
+ '
']
Markdown.has_math = true
when /^\$(.*)\$$/m
o = ["", Regexp.last_match[1], '']
@@ -258,12 +261,19 @@ def self.markdown
@markdown ||= Redcarpet::Markdown.new(renderer, REDCARPET_OPTIONS)
end
+ # Produces
-delimited block content
def self.render(markdown_text, default_language = nil)
renderer.reset
renderer.default_language = default_language
markdown.render(markdown_text)
end
+ # Produces -delimited inline content
+ def self.render_inline(markdown_text, default_language = nil)
+ render(markdown_text, default_language)
+ .sub(%r{^(.*)
$}, '\1')
+ end
+
def self.rendered_returns
renderer.returns
end
@@ -275,7 +285,7 @@ def self.rendered_parameters
class JazzyCopyright < Redcarpet::Render::HTML
def link(link, _title, content)
%(#{content})
+rel="external noopener">#{content})
end
end
diff --git a/lib/jazzy/themes/apple/templates/doc.mustache b/lib/jazzy/themes/apple/templates/doc.mustache
index 32c097ce3..41337ce96 100644
--- a/lib/jazzy/themes/apple/templates/doc.mustache
+++ b/lib/jazzy/themes/apple/templates/doc.mustache
@@ -29,7 +29,7 @@
{{module_name}} Reference
-
+
{{name}} {{kind}} Reference
@@ -85,5 +85,4 @@