From 5270dfef3a9d72bac322b044807b686d052a81be Mon Sep 17 00:00:00 2001 From: bevilj Date: Sun, 18 Nov 2018 17:39:51 +0000 Subject: [PATCH] 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 --- .../ch/usi/inf/atelier/group1/HtmlParser.kt | 9 ++- .../group1/jekyll/HtmlToLatexWriter.kt | 34 ++++++++--- .../src/ch/usi/inf/atelier/group1/util/Log.kt | 2 +- site/pages/cmd/advanced/colrm.html | 2 +- site/pages/cmd/advanced/comm.html | 4 +- site/pages/cmd/advanced/grep.html | 4 +- site/pages/cmd/advanced/nl.html | 4 +- site/pages/cmd/advanced/paste-cat.html | 58 ------------------- site/pages/cmd/advanced/vi.html | 2 +- site/pages/cmd/basic/info.html | 4 +- site/pages/cmd/basic/more-less.html | 4 +- site/pages/cmd/basic/open.html | 2 +- site/pages/cmd/basic/say.html | 6 +- site/pages/cmd/interm/install.html | 4 +- site/pages/cmd/interm/md5.html | 2 +- site/pages/cmd/interm/ping.html | 4 +- site/pages/cmd/interm/ssh.html | 4 +- site/pages/cmd/interm/who.html | 13 +++-- site/pages/fs/rm.html | 4 +- site/pages/info/navigation.html | 4 +- site/pages/info/people.html | 2 - site/pages/info/project.html | 55 ++++++++++-------- site/pages/scripts/arrays.html | 11 ++-- site/pages/scripts/for-loop.html | 6 +- 24 files changed, 107 insertions(+), 137 deletions(-) delete mode 100644 site/pages/cmd/advanced/paste-cat.html diff --git a/bonus2/src/ch/usi/inf/atelier/group1/HtmlParser.kt b/bonus2/src/ch/usi/inf/atelier/group1/HtmlParser.kt index 6b01a06..6b21b50 100644 --- a/bonus2/src/ch/usi/inf/atelier/group1/HtmlParser.kt +++ b/bonus2/src/ch/usi/inf/atelier/group1/HtmlParser.kt @@ -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()) { diff --git a/bonus2/src/ch/usi/inf/atelier/group1/jekyll/HtmlToLatexWriter.kt b/bonus2/src/ch/usi/inf/atelier/group1/jekyll/HtmlToLatexWriter.kt index bebe650..fc153c1 100644 --- a/bonus2/src/ch/usi/inf/atelier/group1/jekyll/HtmlToLatexWriter.kt +++ b/bonus2/src/ch/usi/inf/atelier/group1/jekyll/HtmlToLatexWriter.kt @@ -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("
", "
", "\\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)"), "") + .replace("", "") + } + /** * 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("&", "<", ">", "'") - private val HTML_SPECIALS_TO = arrayOf("\\&", "\\textless ", "\\textgreater ", "\'") + private val SPECIAL_CHARS_HTML = + arrayOf("&", "<", ">", "'", + "©", "\\n", "[", "]", + "\$", "_", "#", "%", + "^") + private val SPECIAL_CHARS_LATEX = + arrayOf("\\&", "\\textless ", "\\textgreater ", "\'", + "(c)", "\\\\n", "\\[", "\\]", + "\\\$", "\\_", "\\#", "\\%", + "\\^") } } diff --git a/bonus2/src/ch/usi/inf/atelier/group1/util/Log.kt b/bonus2/src/ch/usi/inf/atelier/group1/util/Log.kt index 23f1bfc..f01e3e7 100644 --- a/bonus2/src/ch/usi/inf/atelier/group1/util/Log.kt +++ b/bonus2/src/ch/usi/inf/atelier/group1/util/Log.kt @@ -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 e(exception: T, shouldThrow: Boolean) { diff --git a/site/pages/cmd/advanced/colrm.html b/site/pages/cmd/advanced/colrm.html index 4a5a3e1..2f365b0 100644 --- a/site/pages/cmd/advanced/colrm.html +++ b/site/pages/cmd/advanced/colrm.html @@ -10,7 +10,7 @@ The colrm is a command that removes the column that you indicate example.txt that contains two lines to test this command:
-{% highlight bash linenos %} +{% highlight bash %} 123456789 abcdefghi {% endhighlight %} diff --git a/site/pages/cmd/advanced/comm.html b/site/pages/cmd/advanced/comm.html index 866ff0f..28a1d64 100644 --- a/site/pages/cmd/advanced/comm.html +++ b/site/pages/cmd/advanced/comm.html @@ -13,7 +13,7 @@ Here we have two files named example1.txt and example2.txt that contain 5 elements, to test this command:
example1.txt -{% highlight bash linenos %} +{% highlight bash %} Icecream Chocolate Cake @@ -22,7 +22,7 @@ Biscuit {% endhighlight %} example2.txt -{% highlight bash linenos %} +{% highlight bash %} Bread Chocolate Tomato diff --git a/site/pages/cmd/advanced/grep.html b/site/pages/cmd/advanced/grep.html index 907f030..b9ee05f 100644 --- a/site/pages/cmd/advanced/grep.html +++ b/site/pages/cmd/advanced/grep.html @@ -15,7 +15,7 @@ Here we have two files named example1.txt and example2.txt that contain 5 elements, to test this command: example1.txt -{% highlight bash linenos %} +{% highlight bash %} Car Computer Robot @@ -24,7 +24,7 @@ Videogame {% endhighlight %} example2.txt -{% highlight bash linenos %} +{% highlight bash %} Apple Computer Robot diff --git a/site/pages/cmd/advanced/nl.html b/site/pages/cmd/advanced/nl.html index 4b5df53..b2a55ed 100644 --- a/site/pages/cmd/advanced/nl.html +++ b/site/pages/cmd/advanced/nl.html @@ -11,7 +11,7 @@ Through some flags you can decide how to filter this command.
We have a file named example.txt 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 - p^[cv] 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.
  • -bn: The flag n goes with b, doesn't number any lines diff --git a/site/pages/cmd/advanced/paste-cat.html b/site/pages/cmd/advanced/paste-cat.html deleted file mode 100644 index a18f110..0000000 --- a/site/pages/cmd/advanced/paste-cat.html +++ /dev/null @@ -1,58 +0,0 @@ ---- -layout: page -author: Agostino Monti -category-page: advanced -category-title: Advanced commands -tags: filie coluns analize -title: paste ---- - -
    -
    -

    paste 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, paste 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, paste will output a newline - character and move on to the next line.

    - -

    cat

    -

    cat is a standard Unix utility that reads files sequentially, writing them to standard output. - The name is derived from its function to concatenate files.

    - -

    Examples

    -

    -    paste file1.txt file2.txt 
    - cat fail1.txt fail2.txt

    - -

    flags

    -
      -
    • -d 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. -

      Examples

      -
      -        paste -d "|" file1.txt file2.txt
      -        paste -d "|," file1.txt file2.txt
    • - -
    • -s, which causes paste to append the data in serial rather than in parallel; - that is, in a horizontal rather than vertical fashion. -

      Examples

      -
      -        paste -s file1.txt file2.txt
    • - -
    • -u is one option flag, -u for unbuffered output, - meaning that each byte is written after it has been read. -

      Examples

      -
      -        cat -u file1.txt file2.txt
    • - -
    • -n this option numbers all output lines -

      Examples

      -
      -        cat -n file1.txt
      -        cat -n file1.txt file2.txt
    • - - -
    diff --git a/site/pages/cmd/advanced/vi.html b/site/pages/cmd/advanced/vi.html index a7b5340..a50a2c9 100644 --- a/site/pages/cmd/advanced/vi.html +++ b/site/pages/cmd/advanced/vi.html @@ -52,7 +52,7 @@ However, it is also possible to quit vi without saving the file.
    The cursor moves to bottom of screen whenever a colon (:) is typed. This type of command is completed by hitting the -<Return> (or <Enter>) key.
    +<Return> (or <Enter>) key.
     :q
    diff --git a/site/pages/cmd/basic/info.html b/site/pages/cmd/basic/info.html
    index 7b2ac59..2b0635a 100644
    --- a/site/pages/cmd/basic/info.html
    +++ b/site/pages/cmd/basic/info.html
    @@ -17,7 +17,7 @@ and to search for particular information by using special flags.
     
     
     info [flag] [item]
    -

    +

    Look up for a specific string

    Using the --apropos flag followed by a string, you obtain as @@ -33,7 +33,7 @@ you will get a error message. For example:

     info --apropos duck
         info: No available info files have `duck' in their indices.
    -

    +

    An help with this command

    Using the -h flag (which stands for help), you obtain as diff --git a/site/pages/cmd/basic/more-less.html b/site/pages/cmd/basic/more-less.html index b811d2d..2c469f3 100644 --- a/site/pages/cmd/basic/more-less.html +++ b/site/pages/cmd/basic/more-less.html @@ -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.
  • ESC-( LeftArrow Scroll horizontally left N characters, by default half of the screen size, if N is not specified.
  • -
    +

    Jumping

    @@ -63,7 +63,7 @@ They are not. For a single operation there can be multiple commands.

    Go to the (N-th) next tag.
  • T Go to the (N-th) previous tag.
  • -
    +

    Flags

    diff --git a/site/pages/cmd/basic/open.html b/site/pages/cmd/basic/open.html index c61bb3b..156b956 100644 --- a/site/pages/cmd/basic/open.html +++ b/site/pages/cmd/basic/open.html @@ -17,7 +17,7 @@ interface opens. Now you can work on the opened file.
     open path/name-file
    -

    +

    Open a file with a specific application

    Adding the flag -a to the command permit you to decide with diff --git a/site/pages/cmd/basic/say.html b/site/pages/cmd/basic/say.html index 5b6fe5d..2023ea3 100644 --- a/site/pages/cmd/basic/say.html +++ b/site/pages/cmd/basic/say.html @@ -28,7 +28,7 @@ reading the content of that file.
     say -f path/text.txt
    -

    +

    Specify the reading voice

    By writing the flag -v 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
     say -v "Hello world"
    -

    +

    Specify the Speech Rate

    By writing the flag -r followed by a rate and then by a @@ -52,7 +52,7 @@ string, you can decide the reading speed in words per minute.
     ay -r rate string
    -

    +

    Store the output in an audible file

    You can save the result of the command in an audible file. To do that, diff --git a/site/pages/cmd/interm/install.html b/site/pages/cmd/interm/install.html index ca46390..7381080 100644 --- a/site/pages/cmd/interm/install.html +++ b/site/pages/cmd/interm/install.html @@ -15,13 +15,13 @@ Basic syntax is in the form
     install [OPTION]... SOURCE DEST
    -

    + This line of code copies all .xyz file from /source/folder to /destination/folder
     install -D /source/folder/*.xyz /destination/folder
    -

    +

    Flags

    diff --git a/site/pages/cmd/interm/md5.html b/site/pages/cmd/interm/md5.html index 5e3b324..998e089 100644 --- a/site/pages/cmd/interm/md5.html +++ b/site/pages/cmd/interm/md5.html @@ -26,7 +26,7 @@ md5 -s "Hello there"

    Flags

    -
      q +
      • -s: computes the md5 sum of a string instead of a file
      • -q: prints the md5 sum without the file or string name
      • -r: reverses the format of the output
      • diff --git a/site/pages/cmd/interm/ping.html b/site/pages/cmd/interm/ping.html index 7f14ec7..246b8d8 100644 --- a/site/pages/cmd/interm/ping.html +++ b/site/pages/cmd/interm/ping.html @@ -22,14 +22,14 @@ The main usages for the ping command are:
      • Test whether remote server if working.
      • Check the network connectivity from your local machine to a remote one.
      • Check for general network issues.
      • -
          +
         ping theshell.ch
         
        The shell will output something like this: -64 bytes from 98.138.219.232: icmp_seq=0 ttl=49 time=144.781 ms for each packets +64 bytes from 98.138.219.232: icmp_seq=0 ttl=49 time=144.781 ms for each packet that returns (echoed back).
        To stop the ping command press control + c. diff --git a/site/pages/cmd/interm/ssh.html b/site/pages/cmd/interm/ssh.html index 04de4ea..75b41ee 100644 --- a/site/pages/cmd/interm/ssh.html +++ b/site/pages/cmd/interm/ssh.html @@ -23,9 +23,7 @@ remote-server:[~]> Once you're logged in, the local machine shell will be -replaced by the remote server's one - -
        +replaced by the remote server's one.

        Log out of a server

        diff --git a/site/pages/cmd/interm/who.html b/site/pages/cmd/interm/who.html index 107a749..660c195 100644 --- a/site/pages/cmd/interm/who.html +++ b/site/pages/cmd/interm/who.html @@ -19,18 +19,19 @@ Here are just some of the most useful options for this command:
      • -b: Display time of last system boot.
      • -d: Print dead processes.
      • -H: Write column headings above the regular output.
      • -
      • -m: Only print information about the current terminal. This is the - POSIX way of saying who am i.
      • +
      • -m: Only print information about the current terminal.
      • -q: Quick mode: List only the names and the number of users currently logged on. When this option is used, all other options are - ignored.
      • + ignored. +
      • -s: List only the name, line and time fields. This is the default.
      • -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.
      • + and "?" if a bad line is encountered. +
      • -u: Print the idle time for each user, and the associated process ID.
      • am I: Returns the invoker's real user name. You can also use whoami
      • file: By default, who gathers information from the file /var/run/utmpx. - An alternative file may be specified.
      • -
          + An alternative file may be specified. +
        diff --git a/site/pages/fs/rm.html b/site/pages/fs/rm.html index e06b944..acea064 100644 --- a/site/pages/fs/rm.html +++ b/site/pages/fs/rm.html @@ -14,7 +14,7 @@ It stands for ReMove.
         rm [-dfiPRrvW] file1 file2 file....
        -

        +

        Flags

          @@ -39,7 +39,7 @@ rm [-dfiPRrvW] file1 file2 file....
        • -v: Be verbose when deleting files, showing them as they are removed.
        • -W: Attempt to undelete the named files. Currently, this option can only be used to recover files covered by whiteouts.
        • -

        +

      Removing links

      diff --git a/site/pages/info/navigation.html b/site/pages/info/navigation.html index 2664dbb..659dd87 100644 --- a/site/pages/info/navigation.html +++ b/site/pages/info/navigation.html @@ -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:
      @@ -87,3 +87,5 @@ You can navigate in our website with your keyboard using some tricks:
      Brings you to the about topic page
      + +The navigation shortcuts will not be available when you're doing a search through the search bar. diff --git a/site/pages/info/people.html b/site/pages/info/people.html index 84915b5..1d3c923 100644 --- a/site/pages/info/people.html +++ b/site/pages/info/people.html @@ -7,10 +7,8 @@ author: Joey Bevilacqua title: Who we are --- -

        {% for item in site.authors %}
      • {{ item.name }}: {{ item.position }}
      • {% endfor %}
      -

      diff --git a/site/pages/info/project.html b/site/pages/info/project.html index e3f65b3..e6dfe05 100644 --- a/site/pages/info/project.html +++ b/site/pages/info/project.html @@ -7,27 +7,34 @@ author: Matteo Omenetti title: About the project --- - Timeline of the project -
      - This is the final project of the course “Software Atelier 1” hosted by the University of Lugano.
      - For this project, the informatics students of the first year got divided into two groups, - each made up of 25 students.
      - 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.

      - The students had about 4 weeks to develop, from the ground up, this 100 pages website.
      - 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.
      - 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.
      - 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.
      - 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. +Timeline of the project
      + +This is the final project of the course “Software Atelier 1” hosted by the University of Lugano.
      + +For this project, the informatics students of the first year got divided into two groups, +each made up of 25 students.
      + +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.
      + +The students had about 4 weeks to develop, from the ground up, this 100 pages website.
      + +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.
      + +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.
      + +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.
      + +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. diff --git a/site/pages/scripts/arrays.html b/site/pages/scripts/arrays.html index 2b00d8f..c1f38e3 100644 --- a/site/pages/scripts/arrays.html +++ b/site/pages/scripts/arrays.html @@ -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 "Luigi" at index 12, -"Mario" at index 13 and "Nate" at index 14.
      +Which will create an array with "Luigi" at index 12, +"Mario" at index 13 and "Nate" at index 14.
      An indexed array's selector can also be negative, which will start counting from the end, -so ${names[-1]} means "Nate", ${names[-3] is -"Luigi" and so on.
      +so ${names[-1]} means "Nate", ${names[-3]} is +"Luigi" and so on.
      The other kind of array is an associative array. In an associative array, the values are not mapped to a number but to some other string.
      @@ -102,8 +102,7 @@ is equivalent to "Mario" "Luigi", while ${#names[@]} {% endhighlight %} -counts the number of elements in the array, in this case 3.
      +counts the number of elements in the array, in this case 3.

      -
      Further reading: the bash reference manual diff --git a/site/pages/scripts/for-loop.html b/site/pages/scripts/for-loop.html index 20bd7ca..86ccc59 100644 --- a/site/pages/scripts/for-loop.html +++ b/site/pages/scripts/for-loop.html @@ -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 %}