SciTE and Markdown

1,035 views
Skip to first unread message

Gianfranco

unread,
Mar 28, 2013, 5:34:37 AM3/28/13
to scite-i...@googlegroups.com
Hi,

just wanted to share some experiments I'm doing...
Comments and suggestions are welcome.


# Markdown and SciTE

_How to get a live preview (on Firefox) of a markdown file._

Environment:

 * Windows 7 SP1 64 bit
 * Python 2.6.6
 * SciTE 3.2.5

Prerequisites:

 * [python markdown](http://pythonhosted.org/Markdown/)

Optional packages:

 * [smarty pants](https://pypi.python.org/pypi/mdx_smartypants/1.3), to emit typographically nicer ("curly") quotes, proper ("em" and "en") dashes, etc.;
 * [del/ins](https://pypi.python.org/pypi/mdx_del_ins/1.0),  to support the `del` and `ins` tags.


## SciTE setup

 * pick up a temporary folder to host the markdown previews, e.g. `%UserProfile%\.md`;

 * define the following variables *before* the inclusion of the lua scripts in your `SciTEUser/SciTEGlobal.properties` file:

        python.home=C:\Python26
        python=$(python.home)\python.exe
        python.scripts.dir=$(python.home)\Scripts
        markdown.rendering.command=1121
        markdown.rendering.dir=$(SciteUserHome)\.md
        markdown.rendering.file=$(markdown.rendering.dir)\$(FileName).html

 * to open the markdown preview on the default browser, add these lines:

        command.go.subsystem.$(file.patterns.markdown)=2
        command.go.$(file.patterns.markdown)="$(markdown.rendering.file)"

 * to render it automatically at save time:

    * add the following lines to your `SciTEUser/SciTEGlobal.properties` file:

            file.patterns.markdown=*.md;*.markdown
            filter.markdown=Markdown (md markdown)|$(file.patterns.markdown)|
            command.name.21.$(file.patterns.markdown)=
            command.save.before.21.$(file.patterns.markdown)=2
            command.21.$(file.patterns.markdown)=$(python.scripts.dir)\markdown_py.bat -x extra -x del_ins -x meta -x sane_lists -x smartypants -x toc -x wikilinks -f "$(markdown.rendering.file)" "$(FilePath)"
            user.shortcuts=Ctrl+3|1121|

    * create a `markdown.lua` file in the same folder where your `SciTEStartup.lua` file lives, and copy the following lua fragment:

            function Render()
                if editor.LexerLanguage == "markdown" then
                    scite.MenuCommand(tonumber(props["markdown.rendering.command"]))
                end
            end

            function OnSavePointReached()
                pcall(Render)
                return false
            end

    * add the following line to your `SciTEStartup.lua` file:

            require "markdown"


## Workflow

 * Open an exisiting markdown file or begin with an empty, UTF-8 with BOM encoded file and write some markup text;

 * to start the preview, press F5: your default browser should open the temporary html preview file;

 * to refresh the preview, either:

    * save the markdown file in SciTE, then refresh the preview in the browser;

    * install an extension to let Firefox reload the modified file automatically --- I currently use the [Auto Reload](https://addons.mozilla.org/en-US/firefox/addon/auto-reload) extension, which monitors my `$(SciteUserHome)\.md` folder and reloads any file as it changes.


## Notes

1) begin a lua newby, the `pcall(Render)` call catches the _Editor pane is not accessible at this time_ error that occours at SciTE startup;

2) could not find a better method than `scite.MenuCommand(tonumber(props["markdown.rendering.command"]))` to fire the markdown rendering procedure.


Neil Hodgson

unread,
Mar 28, 2013, 6:35:23 PM3/28/13
to scite-i...@googlegroups.com
Gianfranco:

> * define the following variables *before* the inclusion of the lua scripts in your `SciTEUser/SciTEGlobal.properties` file:

All your settings should be in the user properties file SciTEUser.properties. The global properties file is overwritten each time you install a new version of SciTE but user properties is left alone.

Neil

Gianfranco

unread,
Apr 15, 2013, 4:53:31 AM4/15/13
to scite-i...@googlegroups.com

Il giorno venerdì 12 aprile 2013 23:12:46 UTC+2, thinkstorm ha scritto:
Works like a charm (used the SciTEUser.properties, though).  I made some small changes:

A) add xhtml_wrap to Markdown
https://bitbucket.org/paulprovost/xhtml_wrap


Good catch! A search for a similar wrapper was in my to-do list!
 

BTW: Which Markdown Lexer / .profiles do you use for syntax highlighting?


I currently work with a TextMate's twilight-inspired color scheme
(0x33ff00 identifies styles that I never encountered yet):

[SciTEUser.properties]
import SciTETheme.twilight

if USE_CUSTOM_COLOURS
    style.*.32=$(font.base),$(style.normal)
    style.*.33=$(font.base),$(style.linenr)
    style.*.34=$(style.matchparen)
    style.*.35=$(style.unmatchparen)
    style.*.36=
    style.*.37=$(style.folded)
    style.*.38=$(style.calltips)

#
# markdown
#
style.markdown.32=
# special
style.markdown.1=fore:#33ff00
# **strong**
style.markdown.2=bold
#  __strong__
style.markdown.3=bold
# *emphasis*
style.markdown.4=italics
# _emphasis_
style.markdown.5=italics
# headings
style.markdown.6=fore:#cf6a4c,bold
style.markdown.7=fore:#e9c062,bold
style.markdown.8=fore:#cda869,bold
style.markdown.9=fore:#8f9d6a,bold
style.markdown.10=fore:#7587a6,bold
style.markdown.11=fore:#9b859d,bold
# prechar
style.markdown.12=
# bullets list
style.markdown.13=fore:#4f94cd
# numbered items
style.markdown.14=fore:#4f94cd
# blockquote
style.markdown.15=fore:#9b703f
# ~~strikeout~~
style.markdown.16=
# hrule
style.markdown.17=fore:#f9ee98
# link
style.markdown.18=fore:#cf6a4c
# `code`
style.markdown.19=fore:#a6a6a6
# code-2
style.markdown.20=fore:#33ff00
# code block
style.markdown.21=fore:#a6a6a6
# comment
style.markdown.22=fore:#33ff00
# option
style.markdown.23=fore:#33ff00
# preproc
style.markdown.24=fore:#33ff00
# postproc
style.markdown.25=fore:#33ff00

[SciTETheme.twilight.properties]
# Textmate's twilight colour scheme for SciTE
USE_CUSTOM_COLOURS=1

#
# off_white: #f8f8f8
# black_grey: #141414
# tinted_grey: #3f3c40
# dark_grey: #665f57
# med_grey: #888888
# light_grey: #a6a6a6
# olive_green: #8f9d6a
# washed_orange: #cda869
# faded_violet: #9b859d
# faded_cornwall: #7587a6
# pink_sandstone: #cf6a4c
# steelblue3: #4f94cd
# light_brown: #9b703f
# super_faded_orange: #e9c062
# dark_maroon: #002f29
# yellow: #f9ee98

# SciTE colours
caret.fore=#f8f8f8
caret.line.back=#282828
caret.line.back.alpha=
edge.colour=#282828
selection.fore=#f8f8f8
selection.back=#9b703f
selection.alpha=
whitespace.fore=
whitespace.back=
error.marker.fore=
error.marker.back=#302828
bookmark.fore=
bookmark.back=#282828
bookmark.alpha=
highlight.current.word.colour=#9b703f

# SciTE extra colours
colour.calltiphlt.fore=#4f94cd

style.normal=fore:#f8f8f8,back:#141414
style.boolean=fore:#cf6a4c
style.calltips=fore:#888888,back:#282828
style.character=fore:#8f9d6a,bold
style.comment=fore:#888078,italics
style.conditional=fore:#9b703f,bold
style.constant=fore:#7587a6,bold
#~ style.cursor=fore:#000d18,back:#8faf9f,bold
style.debug=fore:#a52a2a,bold
style.define=fore:#7587a6,bold
style.delimiter=fore:#b8860b
style.diffadd=fore:#8f9d6a,back:#282828,bold
style.diffchange=fore:#cda869,back:#282828
style.diffdelete=fore:#cf6a4c,back:#282828
style.difftext=fore:#f8f8f8,back:#282828,bold
style.directory=fore:#8f9d6a,back:#141414,bold
style.errormsg=fore:#cf6a4c,bold
style.exception=fore:#cf6a4c,bold
style.float=fore:#cf6a4c
style.foldcolumn=fore:#cf6a4c,back:#141414
style.folded=fore:#888888,back:#282828
style.function=fore:#9b5c2e
#~ style.identifier=fore:#7587a6 #!!!
style.incsearch=fore:#4f94cd,back:#f8f8f8
style.keyword=fore:#e9c062,bold
style.label=fore:#9b703f,underline
style.linenr=fore:#665f57,back:#141414
style.macro=fore:#9b703f,bold
style.matchparen=fore:#f9ee98,bold
style.modemsg=fore:#f9ee98
style.moremsg=fore:#f9ee98,bold
style.nontext=fore:#665f57
style.number=fore:#cf6a4c
style.operator=fore:#cda869
style.precondit=fore:#cdc673,bold
style.preproc=fore:#8996a8,bold
#~ style.question=fore:#ffffff,bold
#~ style.repeat=fore:#ffd7a7,bold
#~ style.search=fore:#ffffe0,back:#284f28
style.specialchar=fore:#7587a6,bold
style.specialcomment=fore:#888888,bold,italics
style.special=fore:#cda869
#~ style.specialkey=fore:#9ece9e
style.statement=fore:#cda869
style.statusline=fore:#0e2231,back:#8693a5
style.statuslinenc=fore:#0e2231,back:#8693a5
style.storageclass=fore:#d2b48c,bold
style.string=fore:#8f9d6a
style.structure=fore:#b8860b,bold
style.tag=fore:#cda869
style.title=fore:#cf6a4c,bold
style.todo=fore:#141414,back:#f9ee98,bold
style.typedef=fore:#cda869,bold
style.type=fore:#9b859d,bold
style.underlined=fore:#cf6a4c,underline
style.unmatchparen=fore:#cf6a4c,bold
style.vertsplit=fore:#d5dcee,back:#d5dcee
#~ style.visualnos=fore:#333333,back:#f18c96,bold,underline
style.warningmsg=fore:#cf6a4c,bold
style.wildmenu=fore:#cf6a4c,back:#2c302d,underline

# SciTE extra styles
style.attribute=fore:#f9ee98,bold
style.command=fore:#9b703f
style.section=$(style.float)
style.target=$(style.function)
style.variable=fore:#8f9d6a
style.errorlist=$(style.float)
style.errorlist.cmd=$(style.statement)

style.*.27=$(style.float)

Gianfranco

unread,
Apr 16, 2013, 5:41:26 AM4/16/13
to scite-i...@googlegroups.com


Il giorno lunedì 15 aprile 2013 19:09:59 UTC+2, Thorsten Claus ha scritto:

my fork of Paul's original xhtml_wrap is here https://bitbucket.org/thinkstorm/xhtml_wrap/src, let's see if he pulls it :)  with the setup.py file you can also run "python setup.py install" if you have setuptools/distribute installed.

Just installed your fork.
Thanks for sharing!

Gianfranco

unread,
Apr 14, 2015, 8:32:37 AM4/14/15
to scite-i...@googlegroups.com
Hi all,

i'm bumpin' up this old thread because some modifications are needed
to make it work with the new version of the Python implementation of Markdown.

Environment:

 * Ubuntu 14.04
 * SciTE 3.3.5
 * Python 2.7.6

Update the markdown package with the following command:

    sudo pip install markdown

Install any third party extensions you want:

    sudo pip install mdx_cite
    sudo pip install mdx_ins_del

There's no need to install the mdx_smartypants package, since the Markdown
package now includes a custom implementation;

The mdx_xhtml_wrap package must be installed via github:

cd
hg clone https://bitbucket.org/thinkstorm/xhtml_wrap
cd xhtml_wrap
sudo python setup.py install
cd ..
sudo rm -r xhtml_wrap

Since version 2.6 the Markdown package does not accept in-line configurations:
they must be passed in a YAML/JSON file. The command line becomes:

$(python.scripts.dir)/markdown_py -c $(SciteUserHome)/.scite/markdown_py.json ...

Where `~/.scite/markdown_py.json` is a JSON file that contains the configuration,
for example:

[file: markdown_py.json]

{
    "xhtml_wrap": {
        "configs": {
            "css_url": "md.css",
            "js_url": "",
            "title": ""
        }
    }
}

To open the html preview in the default browser the Ubuntu command differs from
the Windows one:

[file: SciteUser.properties]
...

if PLAT_WIN
    python=C:\Python26\pythonw.exe
    markdown.script=$(python.home)\Scripts\markdown_py.bat
    command.build.$(file.patterns.markdown)="$(markdown.rendering.file)"
if PLAT_UNIX
    python=/usr/bin/python
    markdown.script=/usr/local/bin/markdown_py
    command.build.$(file.patterns.markdown)=x-www-browser $(markdown.rendering.file) &

command.name.21.$(file.patterns.markdown)=
command.save.before.21.$(file.patterns.markdown)=2
command.21.$(file.patterns.markdown)=$(markdown.script) \
-c $(SciteUserHome)/.scite/markdown_py.json -x mdx_del_ins -x mdx_cite \
-x markdown.extensions.extra -x markdown.extensions.meta \
-x markdown.extensions.sane_lists -x markdown.extensions.smarty \
-x markdown.extensions.toc -x markdown.extensions.wikilinks \

-f "$(markdown.rendering.file)" "$(FilePath)"
user.shortcuts=Ctrl+3|1121|

Note 1: the markdown.extensions.toc seems to work properly only with Python 2.7
and later versions; remove it if you are using an older version.

Note 2: the mdx_ins_del and mdx_cite extensions cause a DeprecationWarning,
which can be safely ignored.

Cheers,
Gianfranco

Reply all
Reply to author
Forward
0 new messages