Skip to content
This repository has been archived by the owner on Sep 17, 2019. It is now read-only.

Commit

Permalink
Fix HTML errors
Browse files Browse the repository at this point in the history
Fixes various HTML errors left over from the conversion to Slim.
  • Loading branch information
joegatt committed Sep 3, 2013
1 parent 392b0c7 commit 5a77602
Show file tree
Hide file tree
Showing 20 changed files with 122 additions and 99 deletions.
37 changes: 17 additions & 20 deletions app/assets/stylesheets/themes/default.css.sass
Original file line number Diff line number Diff line change
Expand Up @@ -446,35 +446,31 @@ iframe
size: $body-font-size
weight: normal
a
&:hover
h2
color: $link-hover-color
&:hover *
color: $link-hover-color
blockquote
&:before
color: $link-hover-color
figcaption
color: $link-hover-color
&:before
color: $link-hover-color
&:after
border-color: $link-hover-color
&:last-child
margin-bottom: 0
.tags
ul
+horizontal-list
&:before
+icon-tags
color: $secondary-color
display: inline
float: left
li
a:after
content: ', '
&:last-child
article
.tags
ul
+horizontal-list
&:before
+icon-tags
color: $secondary-color
display: inline
float: left
li
a:after
content: ''
content: ', '
&:last-child
a:after
content: ''
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -709,6 +705,7 @@ iframe
+pull(4, 12)
+first-column
a
display: block
padding-right: 34.38889%

.notes
Expand Down
64 changes: 29 additions & 35 deletions app/helpers/formatting_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ def blurbify(text, books = [], links = [], books_citation_style = 'citation.book
text = deheaderize(text)
text = bookify(text, books, books_citation_style)
text = linkify(text, links, links_citation_style)
text = smartify(text)
clean_up(text)
clean_up_via_dom(text, true)
end

def simple_blurbify(text)
Expand Down Expand Up @@ -91,7 +90,7 @@ def linkify(text, links, citation_style)
path: link_path(link),
accessed_at: (timeago_tag link.updated_at)))
# We replace links in the body copy (look-arounds prevent us catching urls inside anchor tags).
text.gsub!(/(?<=[^"])(#{ link.url })(?=[^"])/,
text.gsub!(/(?!<=")(#{ link.url })(?!=")/,
t(citation_style,
link_text: link.headline,
title: link.headline,
Expand All @@ -103,7 +102,6 @@ def linkify(text, links, citation_style)
end

def annotate(text)
# text.gsub!(/(\[[^\]]*)\[([^\]]*)\]([^\[]*\])/, '\1(\2)\3') # Remove any nested annotations
text.gsub!(/(\[[^\]]*)\[([^\]]*)\]([^\[]*\])/, '\1\3') # Remove any nested annotations
annotations = text.scan(/\[([^\.].*? .*?)\]/)
if !annotations.empty?
Expand All @@ -126,26 +124,32 @@ def clean_up(text, clean_up_dom = true)
.html_safe
end

def clean_up_via_dom(text)
def clean_up_via_dom(text, unwrap_p = false)
text = text.gsub(/ +/m, ' ')
text = hyper_conform(text)
dom = Nokogiri::HTML(text)
dom.css('cite cite').find_all.each { |e| e.replace e.inner_html }
dom.css('a').find_all.each { |e| e.replace e.inner_html if e.attr('href').blank? and e.attr('href').blank? }
dom.css('p').find_all.each { |e| e.remove if e.content.blank? }
dom.css('h2').find_all.each { |e| e.remove if e.content.blank? }
dom.css('header').find_all.each { |e| e.remove if e.content.blank? }
dom.css('section').find_all.each { |e| e.remove if e.content.blank? }
dom.css('a, h2, header, p, section').find_all.each { |e| e.remove if e.content.blank? }
dom.css('h2 p, cite cite').find_all.each { |e| e.replace e.inner_html }
# dom.css('h2').find_all.each { |h| h.content = h.content.gsub(/(<h2>)\d+\.? */, '\1') }
dom.xpath('//text()').find_all.each do |t|
t.content = smartify(t.content)
# t.content = hyper_conform(t.content)
end
# tidy = Nokogiri::XSLT File.open('vendor/tidy.xsl')
# dom = tidy.transform(dom)
dom = indent_dom(dom) if Settings.html.pretty
unwrap_from_paragraph_tag(dom) if unwrap_p
dom.css('body').children.to_html.html_safe
end

def indent_dom(dom)
tidy = Nokogiri::XSLT File.open('vendor/tidy.xsl')
dom = tidy.transform(dom)
end

def unwrap_from_paragraph_tag(dom)
e = dom.at_css('body p')
e ? e.replace(e.inner_html) : dom
end

def smartify(text)
text = smartify_hyphens(text)
text = smartify_quotation_marks(text)
Expand All @@ -172,15 +176,6 @@ def smartify_quotation_marks(text)
.gsub(/"(\w|<)/, "\u201C\\1")
.gsub(/([\w\.\,\?\!>])"/, "\\1\u201D")
.gsub(/(\u2019|\u201C)([\.\,<])/, "\\2\\1")

# .gsub(/'([^']+)'/, "\u2018\\1\u2019") # If quotes are not closed this would trip up.
# .gsub(/"([^"]+)"/, "\u201C\\1\u201D") # Same here.

# .gsub(/(<[^>]*?)'([^']+?)'([^<]*?\>)/, '\\1ATTRIBUTE_QUOTES\\2ATTRIBUTE_QUOTES\\3') # IS THIS STILL NECESSARY SINCE WE@RE DOING IT THROUGH DOM?
# .gsub(/(<[^>]*?)"([^"]+?)"([^<]*?\>)/, '\\1ATTRIBUTE_QUOTES\\2ATTRIBUTE_QUOTES\\3')
# .gsub(/'([^']+)'/, "\u2018\\1\u2019") # If quotes are not closed this would trip up.
# .gsub(/"([^"]+)"/, "\u201C\\1\u201D") # Same here.
# .gsub(/ATTRIBUTE_QUOTES/, '"')
end

def smartify_numbers(text)
Expand Down Expand Up @@ -219,18 +214,17 @@ def sectionize(text)
end

def hyper_conform(text)
text.gsub!(/\s+([\)\n\.\,\?\!])/m, '\1') # Ensure no space before certain punctuation
text.gsub!(/([\(])\s+/m, '\1') # Ensure no space after certain elements
# text.gsub!(/([\.\,\?\!])([a-zA-Z])/m, '\1 \2') # Ensure space after certain punctuation
text.gsub!(/([[:upper:]]{3,})/, '<abbr>\1</abbr>') # Wrap all-caps in <abbr>
text.gsub!(/\b([A-Z]{1})\./, '\1') # Wrap all-caps in <abbr>
# text.gsub!(/(<p>|<li>)([[:lower:]])/) { "#{ $1 }#{ $2.upcase }" } # Always start with a capital
# text.gsub!(/(\.|\?|\!) ([[:lower:]])/) { "#{ $1 }#{ $2.upcase }" } # Always start with a capital
text.gsub!(/(\w)(<\/p>|<\/li>)/, '\1.\2') # Always end with punctuation -- What about verse? __VERSE ? (& lists?)
text.gsub!(/ *(<a href=\"#annotation-.*?<\/a>) *([\.\,\;\?\!])/, '\2\1')
text.gsub!(/ +(<a href=\"#annotation-)/, '\1')

# text.gsub!(/([\.\?\!])(<\/cite>)([\.\?\!])/, '\1\2') # Ensure no double punctuation after titles
text.html_safe
text.gsub(/\s+([\)\n\.\,\?\!])/m, '\1') # Ensure no space before certain punctuation
.gsub(/([\(])\s+/m, '\1') # Ensure no space after certain elements
.gsub(/([\.\,\?\!])([a-zA-Z])/m, '\1 \2') # Ensure space after certain punctuation
.gsub(/([[:upper:]]{3,})/, '<abbr>\1</abbr>') # Wrap all-caps in <abbr>
.gsub(/\b([A-Z]{1})\./, '\1') # Wrap all-caps in <abbr>
.gsub(/(<p>|<li>)([[:lower:]])/) { "#{ $1 }#{ $2.upcase }" } # Always start with a capital
.gsub(/(\.|\?|\!) ([[:lower:]])/) { "#{ $1 }#{ $2.upcase }" } # Always start with a capital
.gsub(/(\w)(<\/p>|<\/li>)/, '\1.\2') # Always end with punctuation -- What about verse? __VERSE ? (& lists?)
.gsub(/ *(<a href=\"#annotation-.*?<\/a>) *([\.\,\;\?\!])/, '\2\1')
.gsub(/ +(<a href=\"#annotation-)/, '\1')
.gsub(/([\.\?\!])(<\/cite>)([\.\?\!])/, '\1\2') # Ensure no double punctuation after titles
.html_safe
end
end
2 changes: 1 addition & 1 deletion app/views/books/_books_list.html.slim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
section.books

header
h6=t('books.title')
h6 = link_to_unless_current t('books.index.title'), books_path

ul
- books.each do |book|
Expand Down
2 changes: 1 addition & 1 deletion app/views/books/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ section
p= classification(@book)
p= links(@book)

/ %iframe{ src: "http://books.google.de/books?id=#{ @book.google_books_id }&lpg=PR1&ots=Hfep-dhu0H&d&pg=PR1&output=embed" }
/ iframe src="http://books.google.de/books?id=#{ @book.google_books_id }&lpg=PR1&ots=Hfep-dhu0H&d&pg=PR1&output=embed"
= render 'citations/citations_list', citations: sort_by_page_reference(@book.notes.publishable.citations), books: @books unless @book.notes.publishable.citations.empty?

Expand Down
2 changes: 1 addition & 1 deletion app/views/citations/_citations_list.html.slim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
section.citations

header
h6=t('citations.index.title')
h6 = link_to_unless_current t('citations.index.title'), citations_path

ul
- citations.each do |citation|
Expand Down
10 changes: 5 additions & 5 deletions app/views/citations/show.html.slim
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
- document_title = "#{ @citation.headline } | #{ t('site.title') }"
- set_meta_tags title: document_title,
| description: @citation.body,
description: @citation.body,
open_graph: { title: @citation.title }

article
section#content lang: lang_attr(@citation.lang), dir: dir_attr(@citation.lang)
section#content lang=lang_attr(@citation.lang) dir=dir_attr(@citation.lang)

= render 'header', title: t('citations.index.title', id: @citation.id), :document_title => document_title
= render 'header', title: t('citations.index.title', id: @citation.id), document_title: document_title

section lang: lang_attr(@citation.lang), dir: dir_attr(@citation.lang)
section lang=lang_attr(@citation.lang) dir=dir_attr(@citation.lang)

- citation_text, attribution = citation_blurb(@citation.clean_body_with_parentheses, 99999)
- citation_text, attribution = citation_blurb(@citation.clean_body_with_parentheses, 999)

figure.citation
blockquote= blurbify(citation_text, @citation.books, @citation.links)
Expand Down

This file was deleted.

4 changes: 0 additions & 4 deletions app/views/citations/styles/default/_blurb.html.slim

This file was deleted.

5 changes: 0 additions & 5 deletions app/views/citations/styles/default/_book_details.html.slim

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/links/_links_admin_list.html.slim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
section.books

header
h6=t('links.title')
h6=t('links.index.title')

table
- links.each do |link|
Expand Down
2 changes: 1 addition & 1 deletion app/views/links/_links_list.html.slim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
section.links

header
h6 = t('links.index.title')
h6 = link_to_unless_current t('links.index.title'), links_path

ul
- links.each do |link|
Expand Down
2 changes: 0 additions & 2 deletions app/views/links/show_channel.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@ section
p.main= @name.titlecase
= link_to @channel, @channel, class: 'url'

/ %p= link_to @channel, "#{ @links_channel.first.protocol }://#{ @channel }"
= render 'links_list', links: @links_channel unless @links_channel.empty?
12 changes: 7 additions & 5 deletions app/views/notes/_annotated_text.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ section.body = text.html_safe
section.annotations

header
h6 = t('notes.sections.annotations')
/ h6 =t('notes.sections.annotations')
= "<h6>#{ t('notes.sections.annotations') }</h6>".html_safe

ol
- annotations.each_with_index do |annotation, index|
li id="annotation-#{ index + 1 }"
= link_to "#annotation-mark-#{ index + 1 }" do
= index + 1
= annotation.html_safe
= "<li id=\"annotation-#{ index + 1 }\"><a href=\"#annotation-mark-#{ index + 1 }\">#{ index + 1 }</a>#{ annotation.html_safe }</li> ".html_safe
/ Problematic whitespace
/ li id="annotation-#{ index + 1 }"
/ a href="#annotation-mark-#{ index + 1 }" = index + 1
/ = annotation.html_safe
2 changes: 1 addition & 1 deletion app/views/notes/_diffed_tag_list.slim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
nav.tags

header
h6= link_to t('tags.title'), tags_path
h6 = link_to t('tags.index.title'), tags_path

ul
- diffed_tag_list.each do |key, value|
Expand Down
4 changes: 2 additions & 2 deletions app/views/notes/_tag_list.html.slim
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
nav.tags

header
h6 = link_to t('tags.title'), tags_path
h6 = link_to t('tags.index.title'), tags_path

ul
- tags.each do |tag|
li = link_to tag.name, tag_path(tag)
li = link_to tag.name, tag_path(tag), rel: 'tag'
2 changes: 1 addition & 1 deletion app/views/notes/_versions_list.html.slim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
nav.versions

header
h6 = t('notes.version.description')
h6 = t('notes.version.title')

ol
- if note.versions.length == 0
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_notes_list.html.slim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
section.notes

header
h6= t('notes.index.title')
h6 = link_to_unless_current t('notes.index.title'), notes_path

ul
- notes.each do |note|
Expand Down
14 changes: 7 additions & 7 deletions app/views/tags/_tags_list.html.slim
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
- if Settings.tags.index.style == 'cloud'
ul.cloud
- tag_cloud(tags, %w(css1 css2 css3 css4)) do |tag, css_class|
= link_to tag.name, tag_path(tag), class: css_class, title: tag.count
- else
ul.tags
section.tags

header
h6 = link_to_unless_current t('tags.index.title'), tags_path

ul
- tags.each do |tag|
li = link_to "#{ tag.name } <span class=\"count\">#{ tag.count }</span>".html_safe, tag_path(tag), rel: 'tag'
li = link_to "#{ tag.name } <span class=\"count\">#{ tag.count }</span>".html_safe, tag_path(tag)
3 changes: 0 additions & 3 deletions config/environments/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@
# Add the fonts path
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')

# See https://github.com/ndbroadbent/turbo-sprockets-rails3
config.assets.expire_after 2.weeks

# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false

Expand Down
47 changes: 47 additions & 0 deletions vendor/tidy.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!-- From: https://gist.github.com/mislav/398334 -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:param name="indent-increment" select="' '"/>

<xsl:template name="newline">
<xsl:text disable-output-escaping="yes">
</xsl:text>
</xsl:template>

<xsl:template match="comment() | processing-instruction()">
<xsl:param name="indent" select="''"/>
<xsl:call-template name="newline"/>
<xsl:value-of select="$indent"/>
<xsl:copy />
</xsl:template>

<xsl:template match="text()">
<xsl:param name="indent" select="''"/>
<xsl:call-template name="newline"/>
<xsl:value-of select="$indent"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>

<xsl:template match="text()[normalize-space(.)='']"/>

<xsl:template match="*">
<xsl:param name="indent" select="''"/>
<xsl:call-template name="newline"/>
<xsl:value-of select="$indent"/>
<xsl:choose>
<xsl:when test="count(child::*) > 0">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="*|text()">
<xsl:with-param name="indent" select="concat ($indent, $indent-increment)"/>
</xsl:apply-templates>
<xsl:call-template name="newline"/>
<xsl:value-of select="$indent"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

0 comments on commit 5a77602

Please sign in to comment.