-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
111 lines (99 loc) · 4.61 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<!-- meta data -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>LaTeX to Moodle Converter</title>
<meta name="author" content="Andrew Li">
<meta name="description" content="Converts LaTeX to Moodle">
<meta name="keywords" content="latex, moodle">
<meta property="og:image" content="icon.png">
<!-- Mini icon on tab -->
<link rel="icon" href="icon.png" type="image/ico">
<!-- css libraries --><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!-- <link rel="stylesheet" href="css/index.css" type="text/css"> -->
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- Leave those next 4 lines if you care about users using IE8 -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<style>
body {
margin: 0;
background-color: beige;
}
main {
margin: 0 auto;
padding: 50px;
max-width: 960px;
min-height: 100vh;
background-color: rgb(255, 255, 255);
}
p {
margin: 10px;
margin-left: 0;
}
.copyButton {
text-align: right;
}
</style>
</head>
<body>
<!--[if lt IE 7]>
<div class="alert alert-warning alert-dismissible show fixed-top" role="alert">
You are using an <strong>outdated</strong> browser. Please upgrade your browser to improve your experience.
<button type="button" class="close">
<span aria-hidden="true">×</span>
</button>
</div>
<![endif]-->
<!-- Main -->
<main>
<h1 style="text-align: center; margin: 40px;">Convert LaTeX to Moodle styled LaTeX</h1>
<div style="height: 50%; width: 100%; display: flex; justify-content: center;">
<textarea style="width: 100%; height: 50%; text-align: left;" rows="14" placeholder="Input LaTeX here" class="form-control" ></textarea>
</div>
<div style="height: 50%;" class="outputSection">
<hr>
<div style="display: flex;justify-content: space-between;">
<p>Output Text:</p>
<button type="button" title="Copy output to clipboard" class="btn btn-primary copyButton">Copy Output to Clipboard 📋</button>
</div>
<code id="output">
</code>
</div>
</main><script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script>
const area = document.querySelector("textarea")
const output = document.getElementById("output")
const button = document.querySelector(".copyButton")
const nonsense = "#*%@^"
let outputString = ""
area.addEventListener('input', () => {
outputString = ""
const newInput = area.value.replaceAll("\\$", nonsense)
let start = true
for (let i = 0; newInput && i < newInput.length; i++) {
if (newInput[i] === "$") {
outputString += start ? "\\(" : "\\)"
start = !start
} else {
outputString += newInput[i]
}
}
// convert nonsense back to regular dollar sign
output.innerText = outputString.replaceAll(nonsense, "$")
}, false)
button.addEventListener('click', () => {
navigator.clipboard.writeText(outputString)
}, false)
</script>
</body>
</html>