Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial import.

  • Loading branch information...
commit 0d19b5c3bc86596d7e5abc436fe6ece6773189d1 0 parents
Paolo Capriotti authored March 13, 2010
2  AUTHORS
... ...
@@ -0,0 +1,2 @@
  1
+Paolo Capriotti <p.capriotti@gmail.com>
  2
+
16  CMakeLists.txt
... ...
@@ -0,0 +1,16 @@
  1
+project(hikki)
  2
+
  3
+add_subdirectory(markdown)
  4
+
  5
+find_package(KDE4 REQUIRED)
  6
+include(KDE4Defaults)
  7
+include_directories(${KDE4_INCLUDES})
  8
+set(src main.cpp
  9
+        mainwindow.cpp
  10
+        note.cpp
  11
+        notebook.cpp
  12
+        webkitpart.cpp)
  13
+kde4_add_executable(hikki ${src})
  14
+
  15
+target_link_libraries(hikki markdown ${KDE4_KDEUI_LIBS} kparts ktexteditor QtWebKit)
  16
+install(TARGETS hikki ${INSTALL_TARGETS_DEFAULT_ARGS})
22  COPYING
... ...
@@ -0,0 +1,22 @@
  1
+Copyright (c) 2010  Paolo Capriotti <p.capriotti@gmail.com>
  2
+
  3
+Redistribution and use in source and binary forms, with or without
  4
+modification, are permitted provided that the following conditions
  5
+are met:
  6
+
  7
+1. Redistributions of source code must retain the above copyright
  8
+   notice, this list of conditions and the following disclaimer.
  9
+2. Redistributions in binary form must reproduce the above copyright
  10
+   notice, this list of conditions and the following disclaimer in the
  11
+   documentation and/or other materials provided with the distribution.
  12
+
  13
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  14
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  15
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  16
+IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  17
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  18
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  19
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  20
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  22
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7  README.markdown
Source Rendered
... ...
@@ -0,0 +1,7 @@
  1
+# Hikki - minimalistic note-taking tool
  2
+
  3
+*Hikki* is a simple local wiki based on [Markdown](http://daringfireball.net/projects/markdown/), [Kate](http://kate-editor.org/) and [Webkit](http://webkit.org/).
  4
+
  5
+### Acknowledgments
  6
+
  7
+This product includes software developed by David Loren Parsons [http://www.pell.portland.or.us/~orc].
78  example.css
... ...
@@ -0,0 +1,78 @@
  1
+body {
  2
+  font-family: sans-serif "Bitstream Vera Sans";
  3
+  line-height: 1.6em;
  4
+  padding: 0 1em 0 1em;
  5
+  color: #ccc;
  6
+  background-color: #333;
  7
+}
  8
+
  9
+h1, h2, h3, h4, h5, h6 {
  10
+  color: #bbb;
  11
+}
  12
+
  13
+
  14
+h3, h2, h1 {
  15
+    padding: 0.2em 0 0.2em 0.5em;
  16
+    border-width: 1px 1px 1px 0.5em;
  17
+    border-style: solid;
  18
+    border-color: #1a1a1a;
  19
+}
  20
+
  21
+h3 {
  22
+    border-left-width: 0.1em;
  23
+}
  24
+
  25
+h2 {
  26
+    font-size: 1.6em;
  27
+}
  28
+
  29
+h1 { 
  30
+  font-size: 2.5em;
  31
+}
  32
+
  33
+li {
  34
+  padding: 0;
  35
+  margin: 0;
  36
+  list-style-type: square;
  37
+}
  38
+
  39
+a {
  40
+  color: #8e8aFF;
  41
+  font-weight: normal;
  42
+  text-decoration: underline;
  43
+}
  44
+
  45
+a[href^="http://"] {
  46
+  background:url(hikki://data/external.png)
  47
+  99% 40% no-repeat; 
  48
+  padding-right: 15px;
  49
+}
  50
+
  51
+a.broken {
  52
+  color: red;
  53
+}
  54
+
  55
+pre {
  56
+  font-family: "DejaVu Sans Mono";
  57
+  line-height: 1.4em;
  58
+  color: black;
  59
+  background-color: #edf1f4;
  60
+  padding: 2px 10px 2px 10px;
  61
+  margin-left: 0.8em;
  62
+  border: 1px solid #93aabb;
  63
+}
  64
+
  65
+code {
  66
+/*     font-family: monospace; */
  67
+}
  68
+
  69
+.comment { color: #aaa; font-style: italic; }
  70
+.keyword { color: #eff; font-weight: bold; }
  71
+.punct { color: #eee; font-weight: bold; }
  72
+.symbol { color: #0bb; }
  73
+.string { color: #6b4; }
  74
+.ident { color: #ff8; }
  75
+.constant { color: #66f; }
  76
+.regex { color: #ec6; }
  77
+.number { color: #F99; }
  78
+.expr { color: #227; }
30  hikkiui.rc
... ...
@@ -0,0 +1,30 @@
  1
+<!DOCTYPE kpartgui SYSTEM 'kpartgui.dtd'>
  2
+<kpartgui version="17" name="hikki" >
  3
+ <MenuBar>
  4
+  <Menu name="file" >
  5
+   <Action name="edit_mode" />
  6
+   <Action name="display_mode" />
  7
+  </Menu>
  8
+  <Menu name="go" >
  9
+   <Text>&amp;Go</Text>
  10
+   <Action name="back" />
  11
+   <Action name="forward" />
  12
+   <Action name="home" />
  13
+  </Menu>
  14
+  <Menu name="bookmarks" />
  15
+  <Menu name="tools" />
  16
+  <Merge/>
  17
+  <Menu name="help" />
  18
+ </MenuBar>
  19
+ <ActionProperties scheme="Default" >
  20
+  <Action shortcut="Alt+2" name="display_mode" />
  21
+  <Action shortcut="Alt+1" name="edit_mode" />
  22
+ </ActionProperties>
  23
+ <ToolBar noMerge="1" name="mainToolBar" >
  24
+  <Action name="edit_mode" />
  25
+  <Action name="display_mode" />
  26
+  <Action name="go_home" />
  27
+  <Action name="go_back" />
  28
+  <Action name="go_forward" />
  29
+ </ToolBar>
  30
+</kpartgui>
65  main.cpp
... ...
@@ -0,0 +1,65 @@
  1
+// Copyright (c) 2010  Paolo Capriotti <p.capriotti@gmail.com>
  2
+// 
  3
+// Redistribution and use in source and binary forms, with or without
  4
+// modification, are permitted provided that the following conditions
  5
+// are met:
  6
+// 
  7
+// 1. Redistributions of source code must retain the above copyright
  8
+//    notice, this list of conditions and the following disclaimer.
  9
+// 2. Redistributions in binary form must reproduce the above copyright
  10
+//    notice, this list of conditions and the following disclaimer in the
  11
+//    documentation and/or other materials provided with the distribution.
  12
+// 
  13
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  14
+// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  15
+// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  16
+// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  17
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  18
+// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  19
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  20
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  22
+// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23
+
  24
+#include <KApplication>
  25
+#include <KAboutData>
  26
+#include <KCmdLineArgs>
  27
+
  28
+#include "mainwindow.h"
  29
+
  30
+int main(int argc, char** argv)
  31
+{
  32
+  KAboutData aboutData(
  33
+    "hikki",
  34
+    0,
  35
+    ki18n("Hikki"),
  36
+    "0.1",
  37
+    ki18n("Minimalistic Note-taking Tool"),
  38
+    KAboutData::License_BSD,
  39
+    ki18n("(c) 2010 Paolo Capriotti"));
  40
+  
  41
+  KCmdLineOptions opt;
  42
+  opt.add("+[notebook]", ki18n("Notebook path"));
  43
+  KCmdLineArgs::addCmdLineOptions(opt);
  44
+
  45
+  KCmdLineArgs::init(argc, argv, &aboutData);
  46
+  KApplication app;
  47
+
  48
+  QString base;
  49
+  if (const char* baseEnv = getenv("HIKKI_DIR")) {
  50
+    base = baseEnv;
  51
+  }
  52
+  else {
  53
+    base = ".";
  54
+  }
  55
+  
  56
+  KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
  57
+  if (args->count() > 0) {
  58
+    base = args->arg(0);
  59
+  }
  60
+  
  61
+  MainWindow* main = new MainWindow(base);
  62
+  main->show();
  63
+  
  64
+  return app.exec();
  65
+}
175  mainwindow.cpp
... ...
@@ -0,0 +1,175 @@
  1
+// Copyright (c) 2010  Paolo Capriotti <p.capriotti@gmail.com>
  2
+// 
  3
+// Redistribution and use in source and binary forms, with or without
  4
+// modification, are permitted provided that the following conditions
  5
+// are met:
  6
+// 
  7
+// 1. Redistributions of source code must retain the above copyright
  8
+//    notice, this list of conditions and the following disclaimer.
  9
+// 2. Redistributions in binary form must reproduce the above copyright
  10
+//    notice, this list of conditions and the following disclaimer in the
  11
+//    documentation and/or other materials provided with the distribution.
  12
+// 
  13
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  14
+// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  15
+// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  16
+// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  17
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  18
+// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  19
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  20
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  22
+// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23
+
  24
+#include "mainwindow.h"
  25
+
  26
+#include <QStackedWidget>
  27
+#include <QWebView>
  28
+#include <KAction>
  29
+#include <KActionCollection>
  30
+#include <QDebug>
  31
+#include <KLocalizedString>
  32
+#include <KTextEditor/EditorChooser>
  33
+#include <KTextEditor/ConfigInterface>
  34
+#include <KTextEditor/View>
  35
+#include <KXMLGUIFactory>
  36
+#include <QApplication>
  37
+
  38
+#include "webkitpart.h"
  39
+
  40
+using namespace KTextEditor;
  41
+
  42
+MainWindow::MainWindow(const QString& base)
  43
+: KParts::MainWindow(0,
  44
+  static_cast<Qt::WindowFlags>(KDE_DEFAULT_WINDOWFLAGS))
  45
+{
  46
+  
  47
+    
  48
+  QPalette palette = qApp->palette();
  49
+  //palette.setBrush(QPalette::Base, Qt::white);
  50
+  palette.setBrush(QPalette::Text, Qt::white);
  51
+  palette.setBrush(QPalette::WindowText, Qt::white);
  52
+  qApp->setPalette(palette);
  53
+  
  54
+  m_stack = new QStackedWidget(this);
  55
+  setCentralWidget(m_stack);
  56
+  
  57
+  m_notebook = new Notebook(base);
  58
+  m_note = m_notebook->index();
  59
+  kDebug() << "note path" << m_note->path();
  60
+  
  61
+  Editor* editor = EditorChooser::editor();
  62
+  Document* doc = editor->createDocument(this);
  63
+  m_editor = qobject_cast<View*>(doc->createView(this));
  64
+  if (KTextEditor::ConfigInterface *iface = 
  65
+    qobject_cast<KTextEditor::ConfigInterface*>(m_editor))
  66
+  {
  67
+    kDebug() << "Setting word wrap";
  68
+    iface->setConfigValue("dynamic-word-wrap", true);
  69
+  }
  70
+      
  71
+
  72
+  m_stack->addWidget(m_editor);
  73
+
  74
+  m_browser = new WebKitPart(this, m_notebook);
  75
+  m_stack->addWidget(m_browser->widget());
  76
+  connect(m_browser, SIGNAL(noteChanged(QString)),
  77
+          this, SLOT(noteChanged(QString)));
  78
+  
  79
+  setupActions();
  80
+  setupGUI();
  81
+  removeUnwantedActions();
  82
+
  83
+  displayMode();
  84
+}
  85
+
  86
+MainWindow::~MainWindow()
  87
+{
  88
+  delete m_notebook;
  89
+}
  90
+
  91
+void MainWindow::setupActions()
  92
+{
  93
+  KAction* editMode = new KAction(
  94
+    KIcon("document-edit"),
  95
+    i18n("&Edit mode"),
  96
+    this);
  97
+  actionCollection()->addAction("edit_mode", editMode);
  98
+  connect(editMode, SIGNAL(triggered()),
  99
+          this, SLOT(editMode()));
  100
+          
  101
+  KAction* displayMode = new KAction(
  102
+    KIcon("document-preview"),
  103
+    i18n("&Display mode"),
  104
+    this);
  105
+  actionCollection()->addAction("display_mode", displayMode);
  106
+  connect(displayMode, SIGNAL(triggered()),
  107
+          this, SLOT(displayMode()));
  108
+          
  109
+  actionCollection()->addAction("go_back",
  110
+    m_browser->view()->pageAction(QWebPage::Back));
  111
+  actionCollection()->addAction("go_forward",
  112
+    m_browser->view()->pageAction(QWebPage::Forward));
  113
+}
  114
+
  115
+void MainWindow::removeUnwantedActions()
  116
+{
  117
+  delete m_editor->action("file_save");
  118
+  delete m_editor->action("file_save_as");
  119
+}
  120
+
  121
+void MainWindow::editMode()
  122
+{
  123
+  refreshEditor();
  124
+  m_stack->setCurrentWidget(m_editor);
  125
+  guiFactory()->addClient(m_editor);
  126
+  m_mode = EditMode;
  127
+}
  128
+
  129
+void MainWindow::refreshEditor()
  130
+{
  131
+  Document* doc = m_editor->document();
  132
+  if (doc) {
  133
+    if (doc->url().isValid())
  134
+      doc->save();
  135
+    kDebug() << m_note->path();
  136
+    KUrl url("file://" + m_note->path());
  137
+    
  138
+    if (doc->url() != url) {
  139
+      kDebug() << url;
  140
+      doc->openUrl(url);
  141
+      doc->setHighlightingMode("markdown");
  142
+    }
  143
+  }
  144
+}
  145
+
  146
+void MainWindow::displayMode()
  147
+{
  148
+  displayCurrentNote();
  149
+  m_stack->setCurrentWidget(m_browser->widget());
  150
+  guiFactory()->removeClient(m_editor);
  151
+  m_mode = DisplayMode;
  152
+}
  153
+
  154
+void MainWindow::displayCurrentNote()
  155
+{
  156
+  kDebug() << m_note->name();
  157
+  Q_ASSERT(m_note);
  158
+  if (m_editor->document()->url().isValid())
  159
+    m_editor->document()->save();
  160
+  displayNote(m_note);
  161
+}
  162
+
  163
+void MainWindow::displayNote(NotePtr note)
  164
+{
  165
+  QString path = note->rendered();
  166
+  m_browser->openNote(path);
  167
+}
  168
+
  169
+void MainWindow::noteChanged(const QString& path)
  170
+{
  171
+  kDebug() << path;
  172
+  m_note = m_notebook->openFromRendered(path);
  173
+  if (m_mode == EditMode)
  174
+    editMode();
  175
+}
71  mainwindow.h
... ...
@@ -0,0 +1,71 @@
  1
+// Copyright (c) 2010  Paolo Capriotti <p.capriotti@gmail.com>
  2
+// 
  3
+// Redistribution and use in source and binary forms, with or without
  4
+// modification, are permitted provided that the following conditions
  5
+// are met:
  6
+// 
  7
+// 1. Redistributions of source code must retain the above copyright
  8
+//    notice, this list of conditions and the following disclaimer.
  9
+// 2. Redistributions in binary form must reproduce the above copyright
  10
+//    notice, this list of conditions and the following disclaimer in the
  11
+//    documentation and/or other materials provided with the distribution.
  12
+// 
  13
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  14
+// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  15
+// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  16
+// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  17
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  18
+// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  19
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  20
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  22
+// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23
+
  24
+#ifndef MAINWINDOW_H
  25
+#define MAINWINDOW_H
  26
+
  27
+#include <QWidget>
  28
+#include <KParts/MainWindow>
  29
+#include "notebook.h"
  30
+#include "note.h"
  31
+
  32
+namespace KTextEditor { class View; }
  33
+class WebKitPart;
  34
+class QStackedWidget;
  35
+class Notebook;
  36
+
  37
+class MainWindow : public KParts::MainWindow
  38
+{
  39
+Q_OBJECT
  40
+  enum Mode
  41
+  {
  42
+    DisplayMode,
  43
+    EditMode
  44
+  };
  45
+
  46
+  void setupActions();
  47
+  void removeUnwantedActions();
  48
+
  49
+  Notebook* m_notebook;
  50
+  NotePtr m_note;
  51
+  
  52
+  QStackedWidget* m_stack;
  53
+  KTextEditor::View* m_editor;
  54
+  WebKitPart* m_browser;
  55
+  
  56
+  Mode m_mode;
  57
+  
  58
+  void refreshEditor();
  59
+public:
  60
+  MainWindow(const QString& base);
  61
+  ~MainWindow();
  62
+public slots:
  63
+  void editMode();
  64
+  void displayMode();
  65
+  
  66
+  void displayNote(NotePtr note);
  67
+  void displayCurrentNote();
  68
+  void noteChanged(const QString& path);
  69
+};
  70
+
  71
+#endif // MAINWINDOW_H
115  markdown.xml
... ...
@@ -0,0 +1,115 @@
  1
+<?xml version="1.0" encoding="UTF-8"?>
  2
+<!--
  3
+	Kate syntax highlight filter for Markdown/MultiMarkdown documents.
  4
+
  5
+	Copyright 2008 Darrin Yeager. http://www.dyeager.org/
  6
+	Dual-Licensed under both GPL and BSD licenses.
  7
+-->
  8
+
  9
+
  10
+<!-- the [^\s]{1} is in the regex to avoid interfering with bullet list which
  11
+	  starts "* item". Thus emphasis/strong MUST be formed like *words here*
  12
+	  with the asterisks next to the beginning of the first word.
  13
+
  14
+	  Match space or newline, followed by "*", followed by one non-space,
  15
+	  followed by anything non-asterisk, followed by "*", followed by
  16
+	  space, end-of-sentence punctuation, or the end of the line.
  17
+-->
  18
+<!DOCTYPE language SYSTEM "language.dtd"
  19
+			 [
  20
+			 <!ENTITY strongregex "(\s|^)[\*]{2}[^\s]{1}[^\*]+[\*]{2}(\s|\.|,|;|:|\-|\?|$)">
  21
+			 <!ENTITY emphasisregex "(\s|^)[\*]{1}[^\s]{1}[^\*]+[\*]{1}(\s|\.|,|;|:|\-|\?|$)">
  22
+			 <!ENTITY hyperlinkregex "\[[^\]\^]+\]\[[^\]]+\]">
  23
+			 <!ENTITY footnoteregex "\[\^[^\]]+\]">
  24
+]>
  25
+
  26
+<language name="Markdown" version="1.1" section="Markup"
  27
+		extensions="*.text;*.md;*.mmd" priority="15"
  28
+		author="Darrin Yeager webmaster@dyeager.org"
  29
+		license="GPL,BSD" >
  30
+	<highlighting>
  31
+		<contexts>
  32
+
  33
+			<context attribute="Normal Text" lineEndContext="#pop" name="Normal Text" >
  34
+				<DetectChar context="blockquote" char="&gt;" column="0"/>
  35
+				<RegExpr attribute="h1" String="^#\s.*[#]?$" />
  36
+				<RegExpr attribute="h2" String="^##\s.*[#]?$" />
  37
+				<RegExpr attribute="h3" String="^###\s.*[#]?$" />
  38
+				<RegExpr attribute="h4" String="^####\s.*[#]?$" />
  39
+				<RegExpr attribute="h5" String="^#####\s.*[#]?$" />
  40
+				<RegExpr attribute="strong" String="&strongregex;" />
  41
+				<RegExpr attribute="emphasis" String="&emphasisregex;" />
  42
+				<RegExpr attribute="code" String="^[\s]{4,}.*$" />
  43
+				<RegExpr context="bullet" String="^\*\s" />
  44
+				<RegExpr context="numlist" String="^[\d]+\.\s" />
  45
+				<RegExpr attribute="reflink" String="^\[[^\]]+\]:.*$"/>
  46
+				<RegExpr attribute="meta" String="^(Title|Author|Date|Copyright|Revision|CSS|LaTeX\ XSLT|Categories|Tags|BaseName|Excerpt):(.*)+$" />
  47
+				<IncludeRules context="inc" />
  48
+			</context>
  49
+
  50
+			<context attribute="blockquote" lineEndContext="#pop" name="blockquote">
  51
+				<RegExpr attribute="bq-strong" String="&strongregex;" />
  52
+				<RegExpr attribute="bq-emphasis" String="&emphasisregex;" />
  53
+				<IncludeRules context="inc" />
  54
+			</context>
  55
+
  56
+			<context attribute="bullet" lineEndContext="#pop" name="bullet" >
  57
+				<RegExpr attribute="bl-strong" String="&strongregex;" />
  58
+				<RegExpr attribute="bl-emphasis" String="&emphasisregex;" />
  59
+				<IncludeRules context="inc" />
  60
+			</context>
  61
+
  62
+			<context attribute="numlist" lineEndContext="#pop" name="numlist" >
  63
+				<RegExpr attribute="nl-strong" String="&strongregex;" />
  64
+				<RegExpr attribute="nl-emphasis" String="&emphasisregex;" />
  65
+				<IncludeRules context="inc" />
  66
+			</context>
  67
+
  68
+			<context attribute="comment" lineEndContext="#stay" name="comment" >
  69
+				<RegExpr String="--&gt;" attribute="comment" context="#pop" endRegion="comment"/>
  70
+			</context>
  71
+
  72
+			<context name="inc" >
  73
+				<RegExpr attribute="code" String="`[^`]+`" />
  74
+				<RegExpr context="comment" String="&lt;!--" beginRegion="comment" />
  75
+				<RegExpr attribute="hyperlink" String="&hyperlinkregex;" />
  76
+				<RegExpr attribute="footnote" String="&footnoteregex;" />
  77
+			</context>
  78
+
  79
+		</contexts>
  80
+
  81
+		<itemDatas>
  82
+			<itemData name="Normal Text" defStyleNum="dsNormal" />
  83
+			<itemData name="emphasis" italic="true" />
  84
+			<itemData name="strong"  bold="true" />
  85
+			<itemData name="h1" defStyleNum="dsFunction" bold="true" />
  86
+			<itemData name="h2" defStyleNum="dsFunction" bold="true" />
  87
+			<itemData name="h3" defStyleNum="dsFunction" bold="true" />
  88
+			<itemData name="h4" defStyleNum="dsFunction" bold="true" />
  89
+			<itemData name="h5" defStyleNum="dsFunction" bold="true" />
  90
+			<itemData name="blockquote" defStyleNum="dsDataType" />
  91
+			<itemData name="bq-emphasis" defStyleNum="dsDataType" italic="true" />
  92
+			<itemData name="bq-strong" defStyleNum="dsDataType" bold="true" />
  93
+			<itemData name="bullet" defStyleNum="dsFloat" />
  94
+			<itemData name="bl-emphasis" defStyleNum="dsFloat" italic="true" />
  95
+			<itemData name="bl-strong" defStyleNum="dsFloat" bold="true" />
  96
+			<itemData name="numlist" defStyleNum="dsFloat" />
  97
+			<itemData name="nl-emphasis" defStyleNum="dsFloat" italic="true" />
  98
+			<itemData name="nl-strong" defStyleNum="dsFloat" bold="true" />
  99
+			<itemData name="comment"  defStyleNum="dsComment" />
  100
+			<itemData name="code" defStyleNum="dsBaseN" />
  101
+			<itemData name="hyperlink" defStyleNum="dsOthers" underline="true" />
  102
+			<itemData name="footnote" defStyleNum="dsOthers" italic="true" />
  103
+			<itemData name="meta"  defStyleNum="dsComment" />
  104
+			<itemData name="reflink" defStyleNum="dsAlert" underline="true" bold="false" />
  105
+		</itemDatas>
  106
+
  107
+    </highlighting>
  108
+
  109
+	 <general>
  110
+		 <comments>
  111
+			 <comment name="multiLine" start="&lt;!--" end="--&gt;" region="comment" />
  112
+		 </comments>
  113
+	 </general>
  114
+
  115
+ </language>
15  markdown/CMakeLists.txt
... ...
@@ -0,0 +1,15 @@
  1
+set(src amalloc.c 
  2
+        Csio.c 
  3
+        css.c 
  4
+        docheader.c 
  5
+        dumptree.c 
  6
+        generate.c 
  7
+        markdown.c 
  8
+        mkdio.c 
  9
+        resource.c 
  10
+        toc.c 
  11
+        version.c 
  12
+        xml.c 
  13
+        xmlpage.c)
  14
+        
  15
+add_library(markdown STATIC ${src})
47  markdown/COPYRIGHT
... ...
@@ -0,0 +1,47 @@
61  markdown/Csio.c
... ...
@@ -0,0 +1,61 @@
  1
+#include <stdio.h>
  2
+#include <string.h>
  3
+#include <stdarg.h>
  4
+#include "cstring.h"
  5
+#include "markdown.h"
  6
+#include "amalloc.h"
  7
+
  8
+
  9
+/* putc() into a cstring
  10
+ */
  11
+void
  12
+Csputc(int c, Cstring *iot)
  13
+{
  14
+    EXPAND(*iot) = c;
  15
+}
  16
+
  17
+
  18
+/* printf() into a cstring
  19
+ */
  20
+int
  21
+Csprintf(Cstring *iot, char *fmt, ...)
  22
+{
  23
+    va_list ptr;
  24
+    int siz=100;
  25
+
  26
+    do {
  27
+	RESERVE(*iot, siz);
  28
+	va_start(ptr, fmt);
  29
+	siz = vsnprintf(T(*iot)+S(*iot), ALLOCATED(*iot)-S(*iot), fmt, ptr);
  30
+	va_end(ptr);
  31
+    } while ( siz > (ALLOCATED(*iot)-S(*iot)) );
  32
+
  33
+    S(*iot) += siz;
  34
+    return siz;
  35
+}
  36
+
  37
+
  38
+/* write() into a cstring
  39
+ */
  40
+int
  41
+Cswrite(Cstring *iot, char *bfr, int size)
  42
+{
  43
+    RESERVE(*iot, size);
  44
+    memcpy(T(*iot)+S(*iot), bfr, size);
  45
+    S(*iot) += size;
  46
+    return size;
  47
+}
  48
+
  49
+
  50
+/* reparse() into a cstring
  51
+ */
  52
+void
  53
+Csreparse(Cstring *iot, char *buf, int size, int flags)
  54
+{
  55
+    MMIOT f;
  56
+    ___mkd_initmmiot(&f, 0);
  57
+    ___mkd_reparse(buf, size, 0, &f);
  58
+    ___mkd_emblock(&f);
  59
+    SUFFIX(*iot, T(f.out), S(f.out));
  60
+    ___mkd_freemmiot(&f, 0);
  61
+}
111  markdown/amalloc.c
... ...
@@ -0,0 +1,111 @@
  1
+/*
  2
+ * debugging malloc()/realloc()/calloc()/free() that attempts
  3
+ * to keep track of just what's been allocated today.
  4
+ */
  5
+
  6
+#include <stdio.h>
  7
+#include <stdlib.h>
  8
+
  9
+#define MAGIC 0x1f2e3d4c
  10
+
  11
+struct alist { int magic, size; struct alist *next, *last; };
  12
+
  13
+static struct alist list =  { 0, 0, 0, 0 };
  14
+
  15
+static int mallocs=0;
  16
+static int reallocs=0;
  17
+static int frees=0;
  18
+
  19
+void *
  20
+acalloc(int size, int count)
  21
+{
  22
+    struct alist *ret = calloc(size + sizeof(struct alist), count);
  23
+
  24
+    if ( ret ) {
  25
+	ret->magic = MAGIC;
  26
+	ret->size = size * count;
  27
+	if ( list.next ) {
  28
+	    ret->next = list.next;
  29
+	    ret->last = &list;
  30
+	    ret->next->last = ret;
  31
+	    list.next = ret;
  32
+	}
  33
+	else {
  34
+	    ret->last = ret->next = &list;
  35
+	    list.next = list.last = ret;
  36
+	}
  37
+	++mallocs;
  38
+	return ret+1;
  39
+    }
  40
+    return 0;
  41
+}
  42
+
  43
+
  44
+void*
  45
+amalloc(int size)
  46
+{
  47
+    return acalloc(size,1);
  48
+}
  49
+
  50
+
  51
+void
  52
+afree(void *ptr)
  53
+{
  54
+    struct alist *p2 = ((struct alist*)ptr)-1;
  55
+
  56
+    if ( p2->magic == MAGIC ) {
  57
+	p2->last->next = p2->next;
  58
+	p2->next->last = p2->last;
  59
+	++frees;
  60
+	free(p2);
  61
+    }
  62
+    else
  63
+	free(ptr);
  64
+}
  65
+
  66
+
  67
+void *
  68
+arealloc(void *ptr, int size)
  69
+{
  70
+    struct alist *p2 = ((struct alist*)ptr)-1;
  71
+    struct alist save;
  72
+
  73
+    if ( p2->magic == MAGIC ) {
  74
+	save.next = p2->next;
  75
+	save.last = p2->last;
  76
+	p2 = realloc(p2, sizeof(*p2) + size);
  77
+
  78
+	if ( p2 ) {
  79
+	    p2->size = size;
  80
+	    p2->next->last = p2;
  81
+	    p2->last->next = p2;
  82
+	    ++reallocs;
  83
+	    return p2+1;
  84
+	}
  85
+	else {
  86
+	    save.next->last = save.last;
  87
+	    save.last->next = save.next;
  88
+	    return 0;
  89
+	}
  90
+    }
  91
+    return realloc(ptr, size);
  92
+}
  93
+
  94
+
  95
+void
  96
+adump()
  97
+{
  98
+    struct alist *p;
  99
+
  100
+
  101
+    for ( p = list.next; p && (p != &list); p = p->next ) {
  102
+	fprintf(stderr, "allocated: %d byte%s\n", p->size, (p->size==1) ? "" : "s");
  103
+	fprintf(stderr, "           [%.*s]\n", p->size, p+1);
  104
+    }
  105
+
  106
+    if ( getenv("AMALLOC_STATISTICS") ) {
  107
+	fprintf(stderr, "%d malloc%s\n", mallocs, (mallocs==1)?"":"s");
  108
+	fprintf(stderr, "%d realloc%s\n", reallocs, (reallocs==1)?"":"s");
  109
+	fprintf(stderr, "%d free%s\n", frees, (frees==1)?"":"s");
  110
+    }
  111
+}
29  markdown/amalloc.h
... ...
@@ -0,0 +1,29 @@
  1
+/*
  2
+ * debugging malloc()/realloc()/calloc()/free() that attempts
  3
+ * to keep track of just what's been allocated today.
  4
+ */
  5
+#ifndef AMALLOC_D
  6
+#define AMALLOC_D
  7
+
  8
+#include "config.h"
  9
+
  10
+#ifdef USE_AMALLOC
  11
+
  12
+extern void *amalloc(int);
  13
+extern void *acalloc(int,int);
  14
+extern void *arealloc(void*,int);
  15
+extern void afree(void*);
  16
+extern void adump();
  17
+
  18
+#define malloc	amalloc
  19
+#define	calloc	acalloc
  20
+#define realloc	arealloc
  21
+#define free	afree
  22
+
  23
+#else
  24
+
  25
+#define adump()	(void)1
  26
+
  27
+#endif
  28
+
  29
+#endif/*AMALLOC_D*/
28  markdown/config.h
... ...
@@ -0,0 +1,28 @@
  1
+/*
  2
+ * configuration for markdown, generated Sun Sep 20 15:59:07 CEST 2009
  3
+ * by paolo@adelie
  4
+ */
  5
+#ifndef __AC_MARKDOWN_D
  6
+#define __AC_MARKDOWN_D 1
  7
+
  8
+
  9
+#define OS_LINUX 1
  10
+#define DWORD	unsigned long
  11
+#define WORD	unsigned short
  12
+#define BYTE	unsigned char
  13
+#define HAVE_BASENAME 1
  14
+#define HAVE_LIBGEN_H 1
  15
+#define HAVE_PWD_H 1
  16
+#define HAVE_GETPWUID 1
  17
+#define HAVE_SRANDOM 1
  18
+#define INITRNG(x) srandom((unsigned int)x)
  19
+#define HAVE_RANDOM 1
  20
+#define COINTOSS() (random()&1)
  21
+#define HAVE_STRCASECMP 1
  22
+#define HAVE_STRNCASECMP 1
  23
+#define HAVE_FCHDIR 1
  24
+#define TABSTOP 4
  25
+#define HAVE_MALLOC_H 1
  26
+#define PATH_SED "/bin/sed"
  27
+
  28
+#endif/* __AC_MARKDOWN_D */
76  markdown/css.c
... ...
@@ -0,0 +1,76 @@
  1
+/* markdown: a C implementation of John Gruber's Markdown markup language.
  2
+ *
  3
+ * Copyright (C) 2009 David L Parsons.
  4
+ * The redistribution terms are provided in the COPYRIGHT file that must
  5
+ * be distributed with this source code.
  6
+ */
  7
+#include <stdio.h>
  8
+#include <string.h>
  9
+#include <stdarg.h>
  10
+#include <stdlib.h>
  11
+#include <time.h>
  12
+#include <ctype.h>
  13
+
  14
+#include "config.h"
  15
+
  16
+#include "cstring.h"
  17
+#include "markdown.h"
  18
+#include "amalloc.h"
  19
+
  20
+
  21
+/*
  22
+ * dump out stylesheet sections.
  23
+ */
  24
+static void
  25
+stylesheets(Paragraph *p, Cstring *f)
  26
+{
  27
+    Line* q;
  28
+
  29
+    for ( ; p ; p = p->next ) {
  30
+	if ( p->typ == STYLE ) {
  31
+	    for ( q = p->text; q ; q = q->next )
  32
+		Cswrite(f, T(q->text), S(q->text));
  33
+		Csputc('\n', f);
  34
+	}
  35
+	if ( p->down )
  36
+	    stylesheets(p->down, f);
  37
+    }
  38
+}
  39
+
  40
+
  41
+/* dump any embedded styles to a string
  42
+ */
  43
+int
  44
+mkd_css(Document *d, char **res)
  45
+{
  46
+    Cstring f;
  47
+
  48
+    if ( res && *res && d && d->compiled ) {
  49
+	CREATE(f);
  50
+	RESERVE(f, 100);
  51
+	stylesheets(d->code, &f);
  52
+			
  53
+			/* HACK ALERT! HACK ALERT! HACK ALERT! */
  54
+	*res = T(f);	/* we know that a T(Cstring) is a character pointer */
  55
+			/* so we can simply pick it up and carry it away, */
  56
+	return S(f);	/* leaving the husk of the Ctring on the stack */
  57
+			/* END HACK ALERT */
  58
+    }
  59
+    return EOF;
  60
+}
  61
+
  62
+
  63
+/* dump any embedded styles to a file
  64
+ */
  65
+int
  66
+mkd_generatecss(Document *d, FILE *f)
  67
+{
  68
+    char *res;
  69
+    int written = EOF, size = mkd_css(d, &res);
  70
+
  71
+    if ( size > 0 )
  72
+	written = fwrite(res, size, 1, f);
  73
+    if ( res )
  74
+	free(res);
  75
+    return (written == size) ? size : EOF;
  76
+}
75  markdown/cstring.h
... ...
@@ -0,0 +1,75 @@
  1
+/* two template types:  STRING(t) which defines a pascal-style string
  2
+ * of element (t) [STRING(char) is the closest to the pascal string],
  3
+ * and ANCHOR(t) which defines a baseplate that a linked list can be
  4
+ * built up from.   [The linked list /must/ contain a ->next pointer
  5
+ * for linking the list together with.]
  6
+ */
  7
+#ifndef _CSTRING_D
  8
+#define _CSTRING_D
  9
+
  10
+#include <string.h>
  11
+#include <stdlib.h>
  12
+
  13
+#include "amalloc.h"
  14
+
  15
+/* expandable Pascal-style string.
  16
+ */
  17
+#define STRING(type)	struct { type *text; int size, alloc; }
  18
+
  19
+#define CREATE(x)	T(x) = (void*)(S(x) = (x).alloc = 0)
  20
+#define EXPAND(x)	(S(x)++)[(S(x) < (x).alloc) \
  21
+			    ? (T(x)) \
  22
+			    : (T(x) = T(x) ? realloc(T(x), sizeof T(x)[0] * ((x).alloc += 100)) \
  23
+					   : malloc(sizeof T(x)[0] * ((x).alloc += 100)) )]
  24
+
  25
+#define DELETE(x)	ALLOCATED(x) ? (free(T(x)), S(x) = (x).alloc = 0) \
  26
+				     : ( S(x) = 0 )
  27
+#define CLIP(t,i,sz)	\
  28
+	    ( ((i) >= 0) && ((sz) > 0) && (((i)+(sz)) <= S(t)) ) ? \
  29
+	    (memmove(&T(t)[i], &T(t)[i+sz], (S(t)-(i+sz)+1)*sizeof(T(t)[0])), \
  30
+		S(t) -= (sz)) : -1
  31
+
  32
+#define RESERVE(x, sz)	T(x) = ((x).alloc > S(x) + (sz) \
  33
+			    ? T(x) \
  34
+			    : T(x) \
  35
+				? realloc(T(x), sizeof T(x)[0] * ((x).alloc = 100+(sz)+S(x))) \
  36
+				: malloc(sizeof T(x)[0] * ((x).alloc = 100+(sz)+S(x))))
  37
+#define SUFFIX(t,p,sz)	\
  38
+	    memcpy(((S(t) += (sz)) - (sz)) + \
  39
+		    (T(t) = T(t) ? realloc(T(t), sizeof T(t)[0] * ((t).alloc += sz)) \
  40
+				 : malloc(sizeof T(t)[0] * ((t).alloc += sz))), \
  41
+		    (p), sizeof(T(t)[0])*(sz))
  42
+
  43
+#define PREFIX(t,p,sz)	\
  44
+	    RESERVE( (t), (sz) ); \
  45
+	    if ( S(t) ) { memmove(T(t)+(sz), T(t), S(t)); } \
  46
+	    memcpy( T(t), (p), (sz) ); \
  47
+	    S(t) += (sz)
  48
+
  49
+/* reference-style links (and images) are stored in an array
  50
+ */
  51
+#define T(x)		(x).text
  52
+#define S(x)		(x).size
  53
+#define ALLOCATED(x)	(x).alloc
  54
+
  55
+/* abstract anchor type that defines a list base
  56
+ * with a function that attaches an element to
  57
+ * the end of the list.
  58
+ *
  59
+ * the list base field is named .text so that the T()
  60
+ * macro will work with it.
  61
+ */
  62
+#define ANCHOR(t)	struct { t *text, *end; }
  63
+#define E(t)		((t).end)
  64
+
  65
+#define ATTACH(t, p)	( T(t) ? ( (E(t)->next = (p)), (E(t) = (p)) ) \
  66
+			       : ( (T(t) = E(t) = (p)) ) )
  67
+
  68
+typedef STRING(char) Cstring;
  69
+
  70
+extern void Csputc(int, Cstring *);
  71
+extern int Csprintf(Cstring *, char *, ...);
  72
+extern int Cswrite(Cstring *, char *, int);
  73
+extern void Csreparse(Cstring *, char *, int, int);
  74
+
  75
+#endif/*_CSTRING_D*/
43  markdown/docheader.c
... ...
@@ -0,0 +1,43 @@
  1
+/*
  2
+ * docheader -- get values from the document header
  3
+ *
  4
+ * Copyright (C) 2007 David L Parsons.
  5
+ * The redistribution terms are provided in the COPYRIGHT file that must
  6
+ * be distributed with this source code.
  7
+ */
  8
+#include "config.h"
  9
+#include <stdio.h>
  10
+#include <stdlib.h>
  11
+#include <ctype.h>
  12
+
  13
+#include "cstring.h"
  14
+#include "markdown.h"
  15
+#include "amalloc.h"
  16
+
  17
+#define afterdle(t)	(T((t)->text) + (t)->dle)
  18
+
  19
+char *
  20
+mkd_doc_title(Document *doc)
  21
+{
  22
+    if ( doc && doc->headers )
  23
+	return afterdle(doc->headers);
  24
+    return 0;
  25
+}
  26
+
  27
+
  28
+char *
  29
+mkd_doc_author(Document *doc)
  30
+{
  31
+    if ( doc && doc->headers && doc->headers->next )
  32
+	return afterdle(doc->headers->next);
  33
+    return 0;
  34
+}
  35
+
  36
+
  37
+char *
  38
+mkd_doc_date(Document *doc)
  39
+{
  40
+    if ( doc && doc->headers && doc->headers->next && doc->headers->next->next )
  41
+	return afterdle(doc->headers->next->next);
  42
+    return 0;
  43
+}
151  markdown/dumptree.c
... ...
@@ -0,0 +1,151 @@
  1
+/* markdown: a C implementation of John Gruber's Markdown markup language.
  2
+ *
  3
+ * Copyright (C) 2007 David L Parsons.
  4
+ * The redistribution terms are provided in the COPYRIGHT file that must
  5
+ * be distributed with this source code.
  6
+ */
  7
+#include <stdio.h>
  8
+#include "markdown.h"
  9
+#include "cstring.h"
  10
+#include "amalloc.h"
  11
+
  12
+struct frame {
  13
+    int indent;
  14
+    char c;
  15
+};
  16
+
  17
+typedef STRING(struct frame) Stack;
  18
+
  19
+static char *
  20
+Pptype(int typ)
  21
+{
  22
+    switch (typ) {
  23
+    case WHITESPACE: return "whitespace";
  24
+    case CODE      : return "code";
  25
+    case QUOTE     : return "quote";
  26
+    case MARKUP    : return "markup";
  27
+    case HTML      : return "html";
  28
+    case DL        : return "dl";
  29
+    case UL        : return "ul";
  30
+    case OL        : return "ol";
  31
+    case LISTITEM  : return "item";
  32
+    case HDR       : return "header";
  33
+    case HR        : return "hr";
  34
+    case TABLE     : return "table";
  35
+    case SOURCE    : return "source";
  36
+    default        : return "mystery node!";
  37
+    }
  38
+}
  39
+
  40
+static void
  41
+pushpfx(int indent, char c, Stack *sp)
  42
+{
  43
+    struct frame *q = &EXPAND(*sp);
  44
+
  45
+    q->indent = indent;
  46
+    q->c = c;
  47
+}
  48
+
  49
+
  50
+static void
  51
+poppfx(Stack *sp)
  52
+{
  53
+    S(*sp)--;
  54
+}
  55
+
  56
+
  57
+static void
  58
+changepfx(Stack *sp, char c)
  59
+{
  60
+    char ch;
  61
+
  62
+    if ( !S(*sp) ) return;
  63
+
  64
+    ch = T(*sp)[S(*sp)-1].c;
  65
+
  66
+    if ( ch == '+' || ch == '|' )
  67
+	T(*sp)[S(*sp)-1].c = c;
  68
+}
  69
+
  70
+
  71
+static void
  72
+printpfx(Stack *sp, FILE *f)
  73
+{
  74
+    int i;
  75
+    char c;
  76
+
  77
+    if ( !S(*sp) ) return;
  78
+
  79
+    c = T(*sp)[S(*sp)-1].c;
  80
+
  81
+    if ( c == '+' || c == '-' ) {
  82
+	fprintf(f, "--%c", c);
  83
+	T(*sp)[S(*sp)-1].c = (c == '-') ? ' ' : '|';
  84
+    }
  85
+    else
  86
+	for ( i=0; i < S(*sp); i++ ) {
  87
+	    if ( i )
  88
+		fprintf(f, "  ");
  89
+	    fprintf(f, "%*s%c", T(*sp)[i].indent + 2, " ", T(*sp)[i].c);
  90
+	    if ( T(*sp)[i].c == '`' )
  91
+		T(*sp)[i].c = ' ';
  92
+	}
  93
+    fprintf(f, "--");
  94
+}
  95
+
  96
+
  97
+static void
  98
+dumptree(Paragraph *pp, Stack *sp, FILE *f)
  99
+{
  100
+    int count;
  101
+    Line *p;
  102
+    int d;
  103
+    static char *Begin[] = { 0, "P", "center" };
  104
+
  105
+    while ( pp ) {
  106
+	if ( !pp->next )
  107
+	    changepfx(sp, '`');
  108
+	printpfx(sp, f);
  109
+
  110
+	d = fprintf(f, "[%s", Pptype(pp->typ));
  111
+	if ( pp->ident )