mirror of
https://github.com/enso-org/enso.git
synced 2024-11-22 11:52:59 +03:00
Add function to generate doc HTML from text (#1023)
This commit is contained in:
parent
f5ffbe8fa7
commit
84e565e8bc
@ -6,6 +6,7 @@ import org.enso.parserservice.Protocol
|
||||
import org.enso.parserservice.Server
|
||||
import org.enso.syntax.text.{
|
||||
AST,
|
||||
DocParser,
|
||||
DocParserHTMLGenerator,
|
||||
DocParserRunner,
|
||||
Parser,
|
||||
@ -56,6 +57,10 @@ case class ParserService() extends Server with Protocol {
|
||||
val doc = DocParserRunner.createDocs(dropMeta)
|
||||
val code = DocParserHTMLGenerator.generateHTMLForEveryDocumented(doc)
|
||||
Protocol.SuccessDoc(code)
|
||||
case DocParserGenerateHtmlFromDoc(code) =>
|
||||
val doc = DocParser.runMatched(code)
|
||||
val htmlCode = DocParserHTMLGenerator.generateHTMLPureDoc(doc)
|
||||
Protocol.SuccessDoc(htmlCode)
|
||||
case _ =>
|
||||
throw new Exception(f"unimplemented request: $request")
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ object Protocol {
|
||||
extends Request
|
||||
final case class ParseRequestWithMetadata(content: String) extends Request
|
||||
final case class DocParserGenerateHtmlSource(program: String) extends Request
|
||||
final case class DocParserGenerateHtmlFromDoc(code: String) extends Request
|
||||
|
||||
sealed trait Response
|
||||
final case class Success(module: SourceFile) extends Response
|
||||
|
@ -33,4 +33,11 @@ object Parse {
|
||||
val htmlCode = DocParserHTMLGenerator.generateHTMLForEveryDocumented(doc)
|
||||
htmlCode
|
||||
}
|
||||
|
||||
@JSExportTopLevel("doc_parser_generate_html_from_doc")
|
||||
def doc_parser_generate_html_from_doc(code: String): String = {
|
||||
val doc = DocParser.runMatched(code)
|
||||
val htmlCode = DocParserHTMLGenerator.generateHTMLPureDoc(doc)
|
||||
htmlCode
|
||||
}
|
||||
}
|
||||
|
@ -305,6 +305,20 @@ object DocParserHTMLGenerator {
|
||||
new String
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to generate HTML File from pure doc comment w/o connection to AST
|
||||
*
|
||||
* @param doc - Doc from Doc Parser
|
||||
* @param cssLink - string containing CSS file name
|
||||
* @return - HTML Code from Doc
|
||||
*/
|
||||
def generateHTMLPureDoc(
|
||||
doc: Doc,
|
||||
cssLink: String = "style.css"
|
||||
): String = {
|
||||
HTML.html(createHTMLHead("", cssLink), HTML.body(doc.html)).toString()
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//// HTML Rendering of Documentation /////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -584,6 +584,42 @@ object Main extends scala.App {
|
||||
println(htmlCode)
|
||||
println("=========================")
|
||||
|
||||
println("===== PURE DOCUMENTATION PARSER AND GENERATOR (W/O AST CONN) =====")
|
||||
val inpOnlyDoc =
|
||||
"""DEPRECATED
|
||||
|REMOVED - replaced by Foo Bar
|
||||
|ADDED
|
||||
|MODIFIED
|
||||
|UPCOMING
|
||||
|ALAMAKOTA a kot ma Ale
|
||||
|This is a test of Enso Documentation Parser. This is a short synopsis.
|
||||
|
|
||||
|Here you can write the body of documentation. On top you can see tags
|
||||
|added to this piece of code. You can customise your text with _Italic_
|
||||
|~Strikethrough~ or *Bold*. ~_*Combined*_~ is funny
|
||||
|
|
||||
|
|
||||
|There are 3 kinds of sections
|
||||
| - Important
|
||||
| - Info
|
||||
| - Example
|
||||
| * You can use example to add multiline code to your documentation
|
||||
|
|
||||
|! Important
|
||||
| Here is a small test of Important Section
|
||||
|
|
||||
|? Info
|
||||
| Here is a small test of Info Section
|
||||
|
|
||||
|> Example
|
||||
| Here is a small test of Example Section
|
||||
| Import Foo
|
||||
| def Bar a
|
||||
|""".stripMargin
|
||||
val doc2 = DocParser.runMatched(inpOnlyDoc)
|
||||
val htmlCode2 = DocParserHTMLGenerator.generateHTMLPureDoc(doc2)
|
||||
println(htmlCode2)
|
||||
|
||||
AST.main()
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user