# # Version 2.5.1 # Copyright 2002, 2004 Thorsten Haude # HTML validification by Joor Loohuis # # This is free software; you may modify and redistribute it under # the terms of the GNU General Public License, Version 2. # (http://www.gnu.org/licenses/gpl.html) # # sh2html(params) # The single parameter is an array containing the following keys: # source source file name; relative pathes ('^[^/]') are prepended # by $PWD (mandatory) # html html file name; relative pathes ('^[^/]') are prepended # by source's dirname (defaults to source".html") # css css file name or "INLINE" for inline css; relative pathes # ('^[^/]') are prepended by source's dirname (defaults to # source".css") # numbered set for applying line numbers (defaults to unset) # mode language mode to use (defaults to whatever your NEdit # comes up with for the source file) # define sh2html { # Setting up options if ($n_args != 1) { # Wrong number of arguments beep() return "" } params = $1 if ("source" in params) { sourceFile = params["source"] if (search_string(sourceFile, "^/", 0, "regex") == -1) { # relative path, prepend by $filepath sourceFile = $file_path sourceFile } } else { # required key missing beep() return "" } if ("html" in params) { htmlFile = params["html"] } else { htmlFile = sourceFile ".html" } if ("css" in params) { cssFile = params["css"] } else { cssFile = sourceFile ".css" } if ("numbered" in params) { numbered = 1 } else { numbered = 0 } # Begin and end of the fragment to work with cursorPos = 0 fragmentEnd = 1 # Array to keep the names of all styles already in CSS stylesInCSS = $empty_array # Setup some bits which will become part of the document tab = " " date = chomp(shell_command("date +%Y-%m-%d", "")) myVersion = "2.5.1" # Set up HTML templates htmlHeader = \ "\n"\ "\n"\ "\n"\ " <filename>\n"\ " \n"\ " \n"\ " \n"\ " \n\n"\ " \n"\ " \n"\ "\n\n"\ "\n"\ "
\n"
    htmlHeader = replace_in_string(htmlHeader, "", \
                                   basename(sourceFile))
    htmlFooter = "\n
\n\n\n" codeTemplate = "\">" # Set up CSS templates if (cssFile == "INLINE") { cssHeader = "", "literal", "wrap") set_cursor_pos($text_length) } else { # Put CSS in its own file and put link in HTML file new() focus_window("last") set_language_mode("CSS") save_as(cssFile) insert_string(cssString) cssLink = "" focus_window(htmlFile) replace_all("", cssLink, "literal") } focus_window(htmlFile) set_cursor_pos($text_length) insert_string(htmlFooter) } # createCSS(neditStyle [, "INLINE"]) # # Helper function for sh2html() # # Parameters are: # $1 Style array as returned by get_style() # $2 (optional) Flag "INLINE" to produce smaller footprint result # define createCSS { if ($n_args == 1) { neditStyle = $1 inline = 0 } else if ($n_args == 2 && $2 == "INLINE") { neditStyle = $1 inline = 1 } else { # Wrong number of arguments beep() return "" } # Get rid of those spaces in the style's names styleName = replace_in_string(neditStyle["style"], "\\s", "_",\ "regex", "copy") # Use a slim template for inline CSS if (inline == 1) { cssTemplate = " . {color: ; "\ "font-weight: ; "\ "font-style: ;}\n" } else { cssTemplate = ".\n"\ "{\n"\ " color: ;\n"\ " font-weight: ;\n"\ " font-style: ;\n"\ "}\n\n" } # Put in name ... cssStyle = replace_in_string(cssTemplate, "", styleName, "copy") # ... color ... cssStyle = replace_in_string(cssStyle, "", neditStyle["rgb"], "copy") # ... boldness ... if (neditStyle["bold"]) { fontWeight = "bold" } else { fontWeight = "normal" } cssStyle = replace_in_string(cssStyle, "", fontWeight, "copy") # ... and italicity. if (neditStyle["italic"]) { fontStyle = "italic" } else { fontStyle = "normal" } cssStyle = replace_in_string(cssStyle, "", fontStyle, "copy") return cssStyle } # padNumber(number, totalLen) # # Helper function for sh2html() # # Parameters are: # $1 a number # $2 the length the number is padded to # define padNumber { if ($n_args != 2) { # Wrong number of arguments beep() return "" } aNumber = $1 totalLen = $2 numberLen = length(aNumber) pad = "" for (i = 0; i < totalLen - numberLen; i++) { pad = pad " " } return pad aNumber } # chomp(str): remove the last character of str if it is a newline define chomp { return replace_in_string($1, "(?n\n$)", "", "regex", "copy") } # basename(str): remove the longest prefix of str ending with a "/" define basename { return replace_in_string($1, "(?n^.*/)", "", "regex", "copy") } # dirname: remove the shortest suffix of str starting with a "/" define dirname { return replace_in_string($1, "/[^/]*$", "", "regex") }