1 # Custom tags for JSDuck 5.x
3 # - https://github.com/senchalabs/jsduck/wiki/Tags
4 # - https://github.com/senchalabs/jsduck/wiki/Custom-tags
5 # - https://github.com/senchalabs/jsduck/wiki/Custom-tags/7f5c32e568eab9edc8e3365e935bcb836cb11f1d
6 require 'jsduck/tag/tag'
8 class CommonTag < JsDuck::Tag::Tag
10 @html_position = POS_DOC + 0.1
14 def parse_doc(scanner, position)
16 return { :tagname => @tagname, :doc => :multiline }
18 text = scanner.match(/.*$/)
19 return { :tagname => @tagname, :doc => text }
23 def process_doc(context, tags, position)
24 context[@tagname] = tags
27 def format(context, formatter)
28 context[@tagname].each do |tag|
29 tag[:doc] = formatter.format(tag[:doc])
34 class SourceTag < CommonTag
42 context[@tagname].map do |source|
44 <h3 class='pa'>Source</h3>
51 class SeeTag < CommonTag
58 def format(context, formatter)
59 position = context[:files][0]
60 context[@tagname].each do |tag|
61 tag[:doc] = '<li>' + render_long_see(tag[:doc], formatter, position) + '</li>'
67 <h3 class="pa">Related</h3>
69 #{ context[@tagname].map { |tag| tag[:doc] }.join("\n") }
74 def render_long_see(tag, formatter, position)
75 if tag =~ /\A([^\s]+)( .*)?\Z/m
77 doc = $2 ? ': ' + $2 : ''
78 return formatter.format("{@link #{name}} #{doc}")
80 JsDuck::Logger.warn(nil, 'Unexpected @see argument: "'+tag+'"', position)
86 class ContextTag < CommonTag
93 def format(context, formatter)
94 position = context[:files][0]
95 context[@tagname].each do |tag|
96 tag[:doc] = render_long_context(tag[:doc], formatter, position)
102 <h3 class="pa">Context</h3>
103 #{ context[@tagname].last[:doc] }
107 def render_long_context(tag, formatter, position)
108 if tag =~ /\A([^\s]+)/m
110 return formatter.format("`context` : {@link #{name}}")
112 JsDuck::Logger.warn(nil, 'Unexpected @context argument: "'+tag+'"', position)