Use highlight.js

This commit is contained in:
Andreas Stadelmeier 2021-11-16 17:11:24 +01:00
parent cff305e0db
commit 0c59de6f63
4 changed files with 1191 additions and 6 deletions

9
default.min.css vendored Normal file
View File

@ -0,0 +1,9 @@
/*!
Theme: Default
Description: Original highlight.js style
Author: (c) Ivan Sagalaev <maniac@softwaremaniacs.org>
Maintainer: @highlightjs/core-team
Website: https://highlightjs.org/
License: see project LICENSE
Touched: 2021
*/pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{background:#f0f0f0;color:#444}.hljs-comment{color:#888}.hljs-punctuation,.hljs-tag{color:#444a}.hljs-tag .hljs-attr,.hljs-tag .hljs-name{color:#444}.hljs-attribute,.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-name,.hljs-selector-tag{font-weight:700}.hljs-deletion,.hljs-number,.hljs-quote,.hljs-selector-class,.hljs-selector-id,.hljs-string,.hljs-template-tag,.hljs-type{color:#800}.hljs-section,.hljs-title{color:#800;font-weight:700}.hljs-link,.hljs-operator,.hljs-regexp,.hljs-selector-attr,.hljs-selector-pseudo,.hljs-symbol,.hljs-template-variable,.hljs-variable{color:#bc6060}.hljs-literal{color:#78a960}.hljs-addition,.hljs-built_in,.hljs-bullet,.hljs-code{color:#397300}.hljs-meta{color:#1f7199}.hljs-meta .hljs-string{color:#4d99bf}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}

1149
highlight.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,8 @@
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="index.css">
<link rel="stylesheet" type="text/css" href="index.css">
<link rel="stylesheet" type="text/css" href="default.min.css">
<title>Type-inference for Featherweight Java</title>
</head>
<body>
@ -17,12 +18,13 @@
self = recursive_monster x } -->
</div>
<div id="right">
<div id="ast-output"></div>
<pre><div id="ast-output"></div></pre>
</div>
</div>
<div id="bottom">
<div id="unify-output"></div>
</div>
<script type="text/javascript" src="highlight.min.js"></script>
<script type="text/javascript" src="target/scala-2.13/fj-typeinference-fastopt/main.js"></script>
<br/>
<p>Credit: the CSS style sheet of this page was shamelessly stolen from <a href="https://github.com/LPTK/simple-algebraic-subtyping">the Simple-sub demo page</a>.</p>

View File

@ -1,12 +1,26 @@
package hb.dhbw
import scala.util.Try
import scala.scalajs.js.annotation.JSExportTopLevel
import scala.scalajs.js.annotation.{JSExportTopLevel, JSGlobal}
import org.scalajs.dom
import org.scalajs.dom.document
import org.scalajs.dom.raw.{Event, TextEvent, UIEvent, HTMLTextAreaElement}
import org.scalajs.dom.raw.{Event, HTMLTextAreaElement, TextEvent, UIEvent}
import scala.scalajs.js
@js.native
@JSGlobal
object hljs extends js.Object {
def highlightAuto(code: String): HLJSResult = js.native
}
// @ScalaJSDefined
class HLJSResult extends js.Object{
val value: String = ""
}
object Main {
def main(args: Array[String]): Unit = {
val source = document.querySelector("#fj-input")
update(source.textContent)
@ -24,14 +38,25 @@ object Main {
val target = document.querySelector("#unify-output")
target.innerHTML = FJTypeinference.typeinference(str).fold(
(error) => error,
(result) => prettyPrintHTML(result)
(result) => hljs.highlightAuto(prettyPrintHTML(result)).value
)
val astOutput = document.querySelector("#ast-output")
astOutput.innerHTML = Parser.parse(str).map( parseTree =>
prettyPrintHTMLAST(ASTBuilder.fromParseTree(parseTree))).merge
hljs.highlightAuto(prettyPrintAST(ASTBuilder.fromParseTree(parseTree))).value
).merge
}
def prettyPrintAST(ast: List[Class]): String = {
ast.map(cl => {
"class " + cl.name + "{\n" +
cl.methods.map(m => {
" "+m.retType +" "+ m.name +"(" + ") {\n"+
" return " + "TODO" + ";\n" +
" }"
}).mkString("\n") + "\n}"
}).mkString("\n")
}
def prettyPrintHTML(c: Class): String = {
"class "+c.name+" extends " + prettyPrintHTML(c.superType) + "{</br>" +