Loading lib/jsduck/doc_formatter.rb +14 −1 Original line number Diff line number Diff line Loading @@ -36,16 +36,21 @@ module JsDuck @relations = {} end # Replaces {@link} and {@img} tags, auto-generates links for # recognized classnames. # # Replaces {@link Class#member link text} in given string with # HTML links pointing to documentation. In addition to the href # attribute links will also contain ext:cls and ext:member # attributes. # # Replaces {@img path/to/image.jpg Alt text} with HTML <img> tag. # # Additionally replaces strings recognized as ClassNames with # links to these classes. So one doesn even need to use the @link # tag to create a link. def replace(input) replace_class_names(replace_link_tags(input)) replace_class_names(replace_img_tags(replace_link_tags(input))) end def replace_link_tags(input) Loading Loading @@ -73,6 +78,14 @@ module JsDuck end end def replace_img_tags(input) input.gsub(/\{@img\s+(\S*?)(?:\s+(.+?))?\}/m) do src = $1 alt = $2 "<img src=\"#{src}\" alt=\"#{alt}\"/>" end end def replace_class_names(input) input.gsub(/(\A|\s)([A-Z][A-Za-z0-9.]*[A-Za-z0-9])(?:(#)([A-Za-z0-9]+))?([.,]?(?:\s|\Z))/m) do before = $1 Loading spec/doc_formatter_spec.rb +14 −0 Original line number Diff line number Diff line Loading @@ -9,6 +9,8 @@ describe JsDuck::DocFormatter do describe "#replace" do # {@link ...} it "replaces {@link Ext.Msg} with link to class" do @formatter.replace("Look at {@link Ext.Msg}").should == 'Look at <a href="Ext.Msg" rel="Ext.Msg">Ext.Msg</a>' Loading Loading @@ -49,6 +51,18 @@ describe JsDuck::DocFormatter do "Look at <a href=\"Ext.Msg\" rel=\"Ext.Msg\">some\ntext</a>" end # {@img ...} it "replaces {@img some/image.png Alt text} with <img> element" do @formatter.replace("Look at {@img some/image.png Alt text}").should == 'Look at <img src="some/image.png" alt="Alt text"/>' end it "replaces {@img some/image.png} with <img> element with empty alt tag" do @formatter.replace("Look at {@img some/image.png}").should == 'Look at <img src="some/image.png" alt=""/>' end # auto-conversion of identifiable ClassNames to links describe "auto-detect" do before do Loading Loading
lib/jsduck/doc_formatter.rb +14 −1 Original line number Diff line number Diff line Loading @@ -36,16 +36,21 @@ module JsDuck @relations = {} end # Replaces {@link} and {@img} tags, auto-generates links for # recognized classnames. # # Replaces {@link Class#member link text} in given string with # HTML links pointing to documentation. In addition to the href # attribute links will also contain ext:cls and ext:member # attributes. # # Replaces {@img path/to/image.jpg Alt text} with HTML <img> tag. # # Additionally replaces strings recognized as ClassNames with # links to these classes. So one doesn even need to use the @link # tag to create a link. def replace(input) replace_class_names(replace_link_tags(input)) replace_class_names(replace_img_tags(replace_link_tags(input))) end def replace_link_tags(input) Loading Loading @@ -73,6 +78,14 @@ module JsDuck end end def replace_img_tags(input) input.gsub(/\{@img\s+(\S*?)(?:\s+(.+?))?\}/m) do src = $1 alt = $2 "<img src=\"#{src}\" alt=\"#{alt}\"/>" end end def replace_class_names(input) input.gsub(/(\A|\s)([A-Z][A-Za-z0-9.]*[A-Za-z0-9])(?:(#)([A-Za-z0-9]+))?([.,]?(?:\s|\Z))/m) do before = $1 Loading
spec/doc_formatter_spec.rb +14 −0 Original line number Diff line number Diff line Loading @@ -9,6 +9,8 @@ describe JsDuck::DocFormatter do describe "#replace" do # {@link ...} it "replaces {@link Ext.Msg} with link to class" do @formatter.replace("Look at {@link Ext.Msg}").should == 'Look at <a href="Ext.Msg" rel="Ext.Msg">Ext.Msg</a>' Loading Loading @@ -49,6 +51,18 @@ describe JsDuck::DocFormatter do "Look at <a href=\"Ext.Msg\" rel=\"Ext.Msg\">some\ntext</a>" end # {@img ...} it "replaces {@img some/image.png Alt text} with <img> element" do @formatter.replace("Look at {@img some/image.png Alt text}").should == 'Look at <img src="some/image.png" alt="Alt text"/>' end it "replaces {@img some/image.png} with <img> element with empty alt tag" do @formatter.replace("Look at {@img some/image.png}").should == 'Look at <img src="some/image.png" alt=""/>' end # auto-conversion of identifiable ClassNames to links describe "auto-detect" do before do Loading