add little ruby helper to convert uris to NMTOKEN, for XHTML compliant fragment identifiers. is there any browser that still relies on the <a name="foo"/> attribute? if so, it can be added back.

This commit is contained in:
Jörn Nettingsmeier 2014-02-02 22:37:04 +01:00
parent 42cb77a1a7
commit 02d432c2ef

View File

@ -165,6 +165,10 @@ module Manual
position ? [current, position, level + 1] : [current]
end
def sanitize_NMTOKEN(s)
'ID'+s.gsub(/[^0-9A-z:_.-]/, '_')
end
def render(context)
@source = '_manual' #context.registers[:site].source
@ -201,7 +205,7 @@ module Manual
erb = ::ERB.new <<-HTML
<dt class="<%= css_classes %>">
<a name="<%= entry[:url] %>" href="<%= entry[:url] %>"><%= entry[:menu_title] %></a>
<a id="<%= sanitize_NMTOKEN(entry[:url]) %>" href="<%= entry[:url] %>"><%= entry[:menu_title] %></a>
</dt>
<dd class="<%= css_classes %>">
<% if entry[:children].any? %>
@ -221,7 +225,7 @@ module Manual
erb = ::ERB.new <<-HTML
<dt class="<%= css_classes %>">
<a name="<%= entry[:url] %>" href="<%= entry[:url] %>"><%= entry[:menu_title] %></a>
<a id="<%= sanitize_NMTOKEN(entry[:url]) %>" href="<%= entry[:url] %>"><%= entry[:menu_title] %></a>
</dt>
<dd class="<%= css_classes %>">
</dd>