bonus2: add support for more special chars and fix syntax of parsed files

git-svn-id: svn+ssh://atelier.inf.usi.ch/home/bevilj/group-1@250 a672b425-5310-4d7a-af5c-997e18724b81
This commit is contained in:
bevilj 2018-11-18 17:39:51 +00:00
parent 5c4c1bdbad
commit 5270dfef3a
24 changed files with 107 additions and 137 deletions

View File

@ -49,6 +49,9 @@ class HtmlParser(private val singlePage: Boolean) {
beginDocument()
}
// Convert special chars
changeSpecialChars()
// Convert html elements
changeBold()
changeBr()
@ -60,14 +63,14 @@ class HtmlParser(private val singlePage: Boolean) {
changeMono()
changeParagraph()
changeSection()
changeSpecials()
changeSubSection()
changeSubSubSection()
changeTable()
changeUnderline()
// Strip html comments
// Strip html comments and images
stripComments()
stripImg()
// Store the converted document
commit()
@ -100,11 +103,13 @@ class HtmlParser(private val singlePage: Boolean) {
content.toString()
}
// No ned to save an empty document
if (document.isEmpty()) {
return
}
val outDir = File("out", if (singlePage) "" else File(outName).parent)
if (!outDir.exists()) {

View File

@ -27,7 +27,8 @@ class HtmlToLatexWriter(private var content: String, private val singlePage: Boo
fun beginDocument() {
insert("\\begin{document}", afterLine = true)
insert("\\maketitle", afterLine = true)
insert("\\tableofcontents\\")
insert("\\tableofcontents", afterLine = true)
insert("\\newpage", afterLine = true)
}
/**
@ -113,7 +114,7 @@ class HtmlToLatexWriter(private var content: String, private val singlePage: Boo
*/
fun changeMono() {
content = content.replaceTag("<pre>", "</pre>", "\\begin{verbatim}", "\\end{verbatim}")
.replaceTag("{% highlight bash %}", "{% endhighlight %}",
.replaceTag("{\\% highlight bash \\%}", "{\\% endhighlight \\%}",
"\\begin{verbatim}", "\\end{verbatim}")
}
@ -142,9 +143,9 @@ class HtmlToLatexWriter(private var content: String, private val singlePage: Boo
/**
* Replace special html chars with LaTeX equivalents
*/
fun changeSpecials() {
HTML_SPECIALS_FROM.forEachIndexed { index, s ->
content = content.replace(s, HTML_SPECIALS_TO[index])
fun changeSpecialChars() {
SPECIAL_CHARS_HTML.forEachIndexed { index, s ->
content = content.replace(s, SPECIAL_CHARS_LATEX[index])
}
}
@ -256,6 +257,14 @@ class HtmlToLatexWriter(private var content: String, private val singlePage: Boo
content = content.replace(Regex("(?s)<!--.*?-->"), "")
}
/**
* Remove the img tags
*/
fun stripImg() {
content = content.replace(Regex("(?s)<img.*?>"), "")
.replace("</img>", "")
}
/**
* Insert content into the document
*
@ -300,9 +309,18 @@ class HtmlToLatexWriter(private var content: String, private val singlePage: Boo
private const val HEADER =
"\\documentclass[hidelinks,12pt,a4paper,numbers=enddot]{scrartcl}\n\n" +
"\\usepackage[margin=2cm]{geometry}\n" +
"\\usepackage{hyperref}"
"\\usepackage{hyperref}\n" +
"\\usepackage[utf8]{inputenc}"
private val HTML_SPECIALS_FROM = arrayOf("&amp;", "&lt;", "&gt;", "&#39;")
private val HTML_SPECIALS_TO = arrayOf("\\&", "\\textless ", "\\textgreater ", "\'")
private val SPECIAL_CHARS_HTML =
arrayOf("&amp;", "&lt;", "&gt;", "&#39;",
"&#169;", "\\n", "[", "]",
"\$", "_", "#", "%",
"^")
private val SPECIAL_CHARS_LATEX =
arrayOf("\\&", "\\textless ", "\\textgreater ", "\'",
"(c)", "\\\\n", "\\[", "\\]",
"\\\$", "\\_", "\\#", "\\%",
"\\^")
}
}

View File

@ -11,7 +11,7 @@ object Log {
/**
* Log an exception as an error
*
* @param message The log message
* @param exception The error exception
* @param shouldThrow Whether the exception should be thrown
*/
fun <T : Exception> e(exception: T, shouldThrow: Boolean) {

View File

@ -10,7 +10,7 @@ The <code>colrm</code> is a command that removes the column that you indicate <b
Here we have a file named <code>example.txt</code> that contains two lines to test this command:<br>
{% highlight bash linenos %}
{% highlight bash %}
123456789
abcdefghi
{% endhighlight %}

View File

@ -13,7 +13,7 @@ Here we have two files named <code>example1.txt</code> and
<code>example2.txt</code> that contain 5 elements, to test this command:<br>
<code>example1.txt</code>
{% highlight bash linenos %}
{% highlight bash %}
Icecream
Chocolate
Cake
@ -22,7 +22,7 @@ Biscuit
{% endhighlight %}
<code>example2.txt</code>
{% highlight bash linenos %}
{% highlight bash %}
Bread
Chocolate
Tomato

View File

@ -15,7 +15,7 @@ Here we have two files named <code>example1.txt</code> and
<code>example2.txt</code> that contain 5 elements, to test this command:
<code>example1.txt</code>
{% highlight bash linenos %}
{% highlight bash %}
Car
Computer
Robot
@ -24,7 +24,7 @@ Videogame
{% endhighlight %}
<code>example2.txt</code>
{% highlight bash linenos %}
{% highlight bash %}
Apple
Computer
Robot

View File

@ -11,7 +11,7 @@ Through some flags you can decide how to filter this command.<br>
We have a file named <code>example.txt</code> that contains 5 elements, to test this command:
{% highlight bash linenos %}
{% highlight bash %}
Car
Computer
Robot
@ -45,7 +45,7 @@ nl -b p^[cv] example.txt
Robot
Smartphone
</pre>
<code>p^[cv]</code> says to nl to number only the lines that start with c and v.
The part after the flag is used to number only the lines that start with c and v.
</li>
<li> -b<b>n</b>: The flag n goes with b, doesn't number any lines

View File

@ -1,58 +0,0 @@
---
layout: page
author: Agostino Monti
category-page: advanced
category-title: Advanced commands
tags: filie coluns analize
title: paste
---
<br>
<br>
<p><code>paste</code> is a Unix command line utility which is used to join files horizontally
(parallel merging) by outputting lines consisting of the sequentially corresponding
lines of each file specified, separated by tabs, to the standard output.
Once involved, <code>paste</code> will read all its file arguments. For each corresponding line,
paste will append the contents of each file at that line to its output along with a tab.
When it has completed its operation for the last file, <code>paste</code> will output a newline
character and move on to the next line.</p>
<h3><code>cat</code></h3>
<p><code>cat</code> is a standard Unix utility that reads files sequentially, writing them to standard output.
The name is derived from its function to con<code>cat</code>enate files.</p>
<h4>Examples</h4>
<p><pre>
paste file1.txt file2.txt <br>
cat fail1.txt fail2.txt</pre></p>
<h3>flags</h3>
<ul>
<li><code>-d</code> delimiters, which specifies a list of delimiters to be used instead of tabs
for separating consecutive values on a single line. Each delimiter is used in turn;
when the list has been exhausted, paste begins again at the first delimiter.
<h4>Examples</h4>
<pre>
paste -d "|" file1.txt file2.txt
paste -d "|," file1.txt file2.txt</pre></li>
<li><code>-s</code>, which causes paste to append the data in serial rather than in parallel;
that is, in a horizontal rather than vertical fashion.
<h4>Examples</h4>
<pre>
paste -s file1.txt file2.txt</pre></li>
<li><code>-u</code> is one option flag, <code>-u</code> for unbuffered output,
meaning that each byte is written after it has been read.
<h4>Examples</h4>
<pre>
cat -u file1.txt file2.txt</pre></li>
<li><code>-n</code> this option numbers all output lines
<h4>Examples</h4>
<pre>
cat -n file1.txt
cat -n file1.txt file2.txt</pre></li>
</ul>

View File

@ -52,7 +52,7 @@ However, it is also possible to quit vi without saving the file.<br>
The cursor moves to bottom of screen whenever a colon (:) is
typed. This type of command is completed by hitting the
&ltReturn&gt (or &ltEnter&gt) key.<br>
&lt;Return&gt; (or &lt;Enter&gt;) key.<br>
<pre>
:q

View File

@ -17,7 +17,7 @@ and to search for particular information by using special flags.
<pre>
info [flag] [item]
</pre><br>
</pre>
<h3>Look up for a specific string</h3>
<p>Using the <code>--apropos</code> flag followed by a string, you obtain as
@ -33,7 +33,7 @@ you will get a error message. For example:
<pre>
info --apropos duck
info: No available info files have `duck' in their indices.
</pre><br>
</pre>
<h3>An help with this command</h3>
Using the <code>-h</code> flag (which stands for help), you obtain as

View File

@ -47,7 +47,7 @@ They are not flags. For a single operation there can be multiple commands.
Scroll horizontally right N characters, by default half of the screen size, if N is not specified.</li>
<li><code> ESC-( LeftArrow </code>
Scroll horizontally left N characters, by default half of the screen size, if N is not specified. </li>
</ul><br>
</ul>
<h3>Jumping</h3>
@ -63,7 +63,7 @@ They are not. For a single operation there can be multiple commands. </p>
Go to the (N-th) next tag. </li>
<li><code> T </code>
Go to the (N-th) previous tag.</li>
</ul><br>
</ul>
<h3>Flags</h3>

View File

@ -17,7 +17,7 @@ interface opens. Now you can work on the opened file.
<pre>
open path/name-file
</pre><br>
</pre>
<h3>Open a file with a specific application</h3>
Adding the flag <code>-a</code> to the command permit you to decide with

View File

@ -28,7 +28,7 @@ reading the content of that file.
<pre>
say -f path/text.txt
</pre><br>
</pre>
<h3>Specify the reading voice</h3>
By writing the flag <code>-v</code> followed by a person name and a string, you
@ -44,7 +44,7 @@ so, by writing a string (eg: "Hello world") as argument of the command
<pre>
say -v "Hello world"
</pre><br>
</pre>
<h3>Specify the Speech Rate</h3>
By writing the flag <code>-r</code> followed by a rate and then by a
@ -52,7 +52,7 @@ string, you can decide the reading speed in words per minute.
<pre>
ay -r rate string
</pre><br>
</pre>
<h3>Store the output in an audible file</h3>
You can save the result of the command in an audible file. To do that,

View File

@ -15,13 +15,13 @@ Basic syntax is in the form
<pre>
install [OPTION]... SOURCE DEST
</pre><br>
</pre>
This line of code copies all .xyz file from <i>/source/folder</i> to <i>/destination/folder</i>
<pre>
install -D /source/folder/*.xyz /destination/folder
</pre><br>
</pre>
<h3>Flags</h3>

View File

@ -26,7 +26,7 @@ md5 -s "Hello there"
<h3>Flags</h3>
<ul>q
<ul>
<li><b>-s</b>: computes the md5 sum of a string instead of a file</li>
<li><b>-q</b>: prints the md5 sum without the file or string name</li>
<li><b>-r</b>: reverses the format of the output</li>

View File

@ -22,14 +22,14 @@ The main usages for the <code>ping</code> command are:
<li>Test whether remote server if working.</li>
<li>Check the network connectivity from your local machine to a remote one.</li>
<li>Check for general network issues.</li>
<ol>
</ol>
<pre>
ping theshell.ch
</pre>
The shell will output something like this:
<i>64 bytes from 98.138.219.232: icmp_seq=0 ttl=49 time=144.781 ms </i>for each packets
<i>64 bytes from 98.138.219.232: icmp_seq=0 ttl=49 time=144.781 ms</i> for each packet
that returns (echoed back).<br>
To stop the ping command press <code>control + c</code>.

View File

@ -23,9 +23,7 @@ remote-server:[~]&gt;
</pre>
Once you're logged in, the local machine shell will be
<i>replaced</i> by the remote server's one
<br>
<i>replaced</i> by the remote server's one.<br>
<h3>Log out of a server</h3>

View File

@ -19,18 +19,19 @@ Here are just some of the most useful options for this command:
<li>-b: Display time of last system boot.</li>
<li> -d: Print dead processes.</li>
<li>-H: Write column headings above the regular output.</li>
<li>-m: Only print information about the current terminal. This is the
POSIX way of saying who am i.</li>
<li>-m: Only print information about the current terminal.</li>
<li>-q: <i>Quick mode</i>: List only the names and the number of users currently logged on.
When this option is used, all other options are
ignored.</li>
ignored.
</li>
<li>-s: List only the name, line and time fields. This is the default.</li>
<li>-T: Print a character after the user name indicating the state of the
terminal line: "+" if the terminal is writable; "-" if it is not;
and "?" if a bad line is encountered.</li>
and "?" if a bad line is encountered.
</li>
<li>-u: Print the idle time for each user, and the associated process ID.</li>
<li>am I: Returns the invoker's real user name. You can also use <code>whoami</code></li>
<li>file: By default, who gathers information from the file /var/run/utmpx.
An alternative file may be specified.</li>
<ul>
An alternative file may be specified.
</li>
</ul>

View File

@ -14,7 +14,7 @@ It stands for <i>ReMove</i>.
<pre>
rm [-dfiPRrvW] file1 file2 file....
</pre><br>
</pre>
<h3>Flags</h3>
<ul>
@ -39,7 +39,7 @@ rm [-dfiPRrvW] file1 file2 file....
<li> <b>-v</b>: Be verbose when deleting files, showing them as they are removed.</li>
<li> <b>-W</b>: Attempt to undelete the named files.
Currently, this option can only be used to recover files covered by whiteouts.</li>
</ul><br>
</ul>
<h3>Removing links</h3>

View File

@ -7,7 +7,7 @@ author: Joey Bevilacqua
title: Navigation
---
You can navigate in our website with your keyboard using some tricks:
You can navigate in our website with your keyboard using some tricks:<br>
<table>
<tr>
@ -87,3 +87,5 @@ You can navigate in our website with your keyboard using some tricks:
<td>Brings you to the about topic page</td>
</tr>
</table>
The navigation shortcuts will not be available when you're doing a search through the search bar.

View File

@ -7,10 +7,8 @@ author: Joey Bevilacqua
title: Who we are
---
<p>
<ul>
{% for item in site.authors %}
<li><b>{{ item.name }}</b>: {{ item.position }}</li>
{% endfor %}
</ul>
</p>

View File

@ -7,27 +7,34 @@ author: Matteo Omenetti
title: About the project
---
<img id="time-line" src="../../assets/info/Timeline.jpg" alt="Timeline of the project" width="500px"</img>
<br>
This is the final project of the course “Software Atelier 1” hosted by the University of Lugano.<br>
For this project, the informatics students of the first year got divided into two groups,
each made up of 25 students.<br>
The goal of this project was to put into practice all the skills obtained during the entire
duration of this course: Latex, HTML, CSS, Unix Shell and SVN.<br><br>
The students had about 4 weeks to develop, from the ground up, this 100 pages website.<br>
A great coordination was needed to develop
such a big website in such a short time. For this reason some students had to take care of
specific tasks, such as managing the SVN repository and developing the CSS templates.<br>
Our topic (Unix Shell) got divided into three macro sections, each taking care of a
number of commands based on their advancement level, therefore there is a basic,
intermediate and advance section commands.<br>
Each macro section had its own leader, that was responsible for overseeing the conduct
of the other team members within his group.
hen each team leader reported back to group leader, that was responsible for the success
of the entire project.<br>
The ultimate goal of this website is to provide, to the future first-year students,
a useful and human readable guide that can guide
them through the learning process of this fundamental tool. This website in intended
to be a guide that can be followed, understood and
found interesting by anyone, since it starts from the really basic concepts of the shell,
all the way to the most advanced and foremost commands.
<img id="time-line" src="../../assets/info/Timeline.jpg" alt="Timeline of the project" width="500px"</img><br>
This is the final project of the course “Software Atelier 1” hosted by the University of Lugano.<br>
For this project, the informatics students of the first year got divided into two groups,
each made up of 25 students.<br>
The goal of this project was to put into practice all the skills obtained during the entire
duration of this course: Latex, HTML, CSS, Unix Shell and SVN.<br>
The students had about 4 weeks to develop, from the ground up, this 100 pages website.<br>
A great coordination was needed to develop
such a big website in such a short time. For this reason some students had to take care of
specific tasks, such as managing the SVN repository and developing the CSS templates.<br>
Our topic (Unix Shell) got divided into three macro sections, each taking care of a
number of commands based on their advancement level, therefore there is a basic,
intermediate and advance section commands.<br>
Each macro section had its own leader, that was responsible for overseeing the conduct
of the other team members within his group.
Then each team leader reported back to group leader, that was responsible for the success
of the entire project.<br>
The ultimate goal of this website is to provide, to the future first-year students,
a useful and human readable guide that can guide
them through the learning process of this fundamental tool. This website in intended
to be a guide that can be followed, understood and
found interesting by anyone, since it starts from the really basic concepts of the shell,
all the way to the most advanced and foremost commands.

View File

@ -51,11 +51,11 @@ If our indices are all sequential and we just want to change the starting index,
names=([12]="Luigi" "Mario" "Nate")
{% endhighlight %}
Which will create an array with <code>"Luigi"</code> at index 12,
<code>"Mario"</code> at index 13 and <code>"Nate"</code> at index 14.<br>
Which will create an array with <i>"Luigi"</i> at index 12,
<i>"Mario"</i> at index 13 and <i>"Nate"</i> at index 14.<br>
An indexed array's selector can also be negative, which will start counting from the end,
so <code>${names[-1]}</code> means <code>"Nate"</code>, <code>${names[-3]</code> is
<code>"Luigi"</code> and so on.<br>
so <i>${names[-1]}</i> means <i>"Nate"</i>, <code>${names[-3]}</code> is
<i>"Luigi"</i> and so on.<br>
The other kind of array is an <i>associative</i> array.
In an associative array, the values are not mapped to a number but to some other string.<br>
@ -102,8 +102,7 @@ is equivalent to <code>"Mario" "Luigi"</code>, while
${#names[@]}
{% endhighlight %}
counts the number of elements in the array, in this case 3.<br>
counts the number of elements in the array, in this case 3.<br><br>
<br>
Further reading: <a href="http://www.gnu.org/software/bash/manual/bashref.html#Arrays">
the bash reference manual</a>

View File

@ -26,9 +26,9 @@ For loops take this form:
{% highlight bash %}
for VARIABLE in 1 2 3 4 5 .. N
do
command1
command2
commandN
command1
command2
commandN
done
{% endhighlight %}
<!-- End of Introduction -->