1 2 3 4 Previous Next 50 Replies Latest reply on Jul 9, 2012 11:30 PM by sboscarine Go to original post
      • 45. Re: Asciidoc is the way forward
        sboscarine

        Jason Porter wrote:

         

        You'd have to use jython and create a maven plugin.

        That's what I wanted to do...I thought I would start with Dan's sample and see if I can package it for others.  I was asking more from the perspective that I got it to work, how can I best share it with the community?

        • 46. Re: Asciidoc is the way forward
          lightguard

          Host it up on GitHub and use Sonatype's OSS repo to sync it to central.

          • 47. Re: Asciidoc is the way forward
            sboscarine

            Dan Allen wrote:

             

            Here are the commands I used to generate the HTML, PDF and Docbook outputs.

             

            HTML:

            asciidoc -b html5 -a icons -a iconsdir=$HOME/opt/asciidoc/images/icons -a theme=flask -a data-uri -a toc2 -a pygments tutorial.asciidoc
            

             

            PDF:

            a2x -fpdf -dbook --fop --icons --icons-dir=$HOME/opt/asciidoc/images/icons tutorial.asciidoc
            

             

            Docbook:

            a2x -fdocbook -dbook --fop --icons --icons-dir=$HOME/opt/asciidoc/images/icons tutorial.asciidoc
            

             

            Btw, yelp (the Gnome help browser) is a pretty good Docbook viewer.

            For anyone trying to run this at home, here's the initial steup needed in Ubuntu 12.04

             

            sudo apt-get install asciidoc source-highlight python-pygments

             

            I don't think python-pygments works in cygwin, though.

            • 48. Re: Asciidoc is the way forward
              dan.j.allen

              python-pygments certainly isn't a prerequistie for using AsciiDoc. AsciiDoc works just as well with GNU source-highlight. The pygments processor just gives you a cleaner approach to syntax highlighting in HTML. Keep in mind, these only apply to HTML output. Neither of them get used for the DocBook or PDF exports.

               

              Another approach is to forgo the syntax highlighting and just use a JavaScript syntax highlighting library. Play around with it, see what works best for you. One isn't more right than the other.

              • 49. Re: Asciidoc is the way forward
                dan.j.allen

                If you are getting:

                 

                 

                asciidoc: WARNING: missing backend conf file: html5.conf

                 

                 

                chances are you have an older version of AsciiDoc. I'm currently using version 8.6.6 (which is also the default in Ubuntu 12.04). I'm using Fedora 16 and 17, which have older versions of asciidoc in the repositories, so I upgraded by downloading the tarball, extracting it to my home directory and adding it to my PATH. Of course, I used the package manager to install the dependencies of AsciiDoc, such as python, dblatex or fop, etc.

                 

                Therefore, my recommendation is:

                 

                • Ubuntu 12.04: use apt-get to install asciidoc
                • Fedora or earlier versions of Ubuntu: download the tarball

                 

                I wouldn't recommend using anything older than 8.6.6 because it's just way better than earlier versions.

                • 50. Re: Asciidoc is the way forward
                  sboscarine

                  So I got a little frustrated running a shell command then switching windows (not adapting well to GNOME 3 in Fedora).  With that in mind, I wrote a super-simple servlet.  Save the form below and the Servlet below on a UNIX box.  It'll run the command and render the result.

                   

                  Here's what I did:

                  1. Setup ASCIIDoc on a linux box.
                  2. Started up AS7 instance on same box, ensured that -b and -bmanagement flags were set for remote access
                  3. Moved over to my windows box (can obviously be any OS).
                  4. Loaded JSP below in browser
                  5. Uploaded ASCIIDoc file and viewed result in browser.
                  6. edited ASCIIDoc file in windows text editor of choice
                  7. hit refresh in browser and saw results updated.

                   

                  Now I can hands this off to our doc team and let them play with ASCIIDoc without installing Linux or cygwin. 

                   

                  asciidoc.jsp

                  <html xmlns="http://www.w3.org/1999/xhtml">
                  <head>
                      <title>ASCIIDoc Servlet</title>
                  </head>
                  <body>
                      <form action="asciidoc" method="post" enctype="multipart/form-data">
                          <table>
                              <tr>
                                  <th>Select ASCIIDoc Input: </th>
                                  <td><input  name="file" type="file"/> </td>
                              </tr>
                          </table>
                          <input type="submit" value="Upload ASCIIDoc input"/>
                      </form>
                   </body>
                  </html>
                  

                   

                  AsciiDoc.java

                  import java.io.BufferedReader;
                  import java.io.File;
                  import java.io.FileNotFoundException;
                  import java.io.FileOutputStream;
                  import java.io.IOException;
                  import java.io.InputStream;
                  import java.io.InputStreamReader;
                  import java.io.PrintWriter;
                  import java.util.UUID;
                  
                  import javax.servlet.RequestDispatcher;
                  import javax.servlet.ServletException;
                  import javax.servlet.annotation.MultipartConfig;
                  import javax.servlet.annotation.WebServlet;
                  import javax.servlet.http.HttpServlet;
                  import javax.servlet.http.HttpServletRequest;
                  import javax.servlet.http.HttpServletResponse;
                  import javax.servlet.http.Part;
                  
                  /**
                   * Uploads ASCIIDoc input and performs RequestDispatcher forward to results.
                   * 
                   * @author Steven Boscarine
                   * 
                   */
                  @WebServlet(name = "asciiDoc", urlPatterns = "/asciidoc")
                  // replaces config in web.xml
                  @MultipartConfig
                  // specifies servlet takes multipart/form-data
                  public class AsciiDoc extends HttpServlet {
                      private static final String FILE_UPLOAD_FIELD_NAME = "file";
                      private static final String ASCIIDOC_COMMAND = "asciidoc -b html5 -d book -a icons  -a theme=flask -a data-uri -a toc2 -a pygments ";
                  
                      @Override
                      protected final void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException,
                              IOException {
                          //if we make the filename unique, this application is concurrent.  1 user cannot overwrite the other's input.
                          final String uniqueIdentifier = UUID.randomUUID().toString();
                          final String asciidocInputFileName = "in" + uniqueIdentifier + ".asciidoc";
                          final String asciidocOutputFileName = "/in" + uniqueIdentifier + ".html";
                          response.setContentType("text/html;charset=UTF-8");
                          final PrintWriter out = response.getWriter();
                          try {
                              // get access to file that is uploaded from client
                              final Part filePart = request.getPart(FILE_UPLOAD_FIELD_NAME);
                              final InputStream is = filePart.getInputStream();
                              // determine a path that's accessible from web root.
                              final String destinationFileName = this.getServletContext().getRealPath(asciidocInputFileName);
                              // write file from user to web root.
                              writeInputStreamToDisk(is, destinationFileName);
                              //create file object to set deleteOnExit flag.
                              File intputFileReference = new File(destinationFileName);
                              intputFileReference.deleteOnExit();
                              // run command locally.
                              final String cmdResults = executeShellCommand(ASCIIDOC_COMMAND + destinationFileName);
                  
                              //create file object to set deleteOnExit flag.
                              File outputFileReference = new File(getServletContext().getRealPath(asciidocOutputFileName));
                              outputFileReference.deleteOnExit();
                              System.out.println("rendered file to " + outputFileReference.getAbsolutePath());
                  
                              // write results in case of failure.
                              out.println("<pre>" + cmdResults + "</pre>");
                              final RequestDispatcher rd = getServletContext().getRequestDispatcher(asciidocOutputFileName);
                              rd.forward(request, response);
                          } catch (final Exception e) {
                              throw new RuntimeException(e);
                          } finally {
                              out.close();
                          }
                      }
                  
                      private void writeInputStreamToDisk(final InputStream is, final String destinationFileName) throws FileNotFoundException,
                              IOException {
                          final FileOutputStream os = new FileOutputStream(destinationFileName);
                          // write bytes taken from uploaded file to target file
                          int ch = is.read();
                          while (ch != -1) {
                              os.write(ch);
                              ch = is.read();
                          }
                          os.close();
                      }
                  
                      public String executeShellCommand(final String cmd) {
                          final StringBuilder sb = new StringBuilder();
                          final StringBuilder error = new StringBuilder();
                          try {
                              String line;
                              final Process p = Runtime.getRuntime().exec(cmd);
                              final BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream()));
                              final BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream()));
                              while ((line = bri.readLine()) != null) {
                                  sb.append(line);
                              }
                              bri.close();
                              while ((line = bre.readLine()) != null) {
                                  error.append(line);
                              }
                              bre.close();
                              if (error.length() > 0) {
                                  System.out.println("The system wrote to standard error!:\n" + error.toString());
                              }
                              p.waitFor();
                          } catch (final Exception e) {
                              throw new RuntimeException(error.toString(), e);
                          }
                          return sb.toString();
                      }
                  
                      private static final long serialVersionUID = 1L;
                  }
                  
                  1 2 3 4 Previous Next