1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Doc down related queries
16 module commands_docdown
18 import templates
::md_commands
21 # Retrieve the MDoc summary
23 # List all MarkdownHeading found and their ids.
27 # Markdown processor used to parse the headlines
28 var markdown_processor
: MarkdownProcessor is writable
32 # Associates each headline to its id.
33 var summary
: nullable ArrayMap[String, HeadLine] = null is optional
, writable
35 redef fun init_command
do
37 if not res
isa CmdSuccess then return res
38 var mentity
= self.mentity
.as(not null)
42 mdoc
= if fallback
then mentity
.mdoc_or_fallback
else mentity
.mdoc
45 if mdoc
== null then return new WarningNoMDoc(mentity
)
47 markdown_processor
.process
(mdoc
.md_documentation
.write_to_string
)
49 var summary
= new ArrayMap[String, HeadLine]
50 summary
.add_all markdown_processor
.decorator
.headlines
51 self.summary
= summary