Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed plugin names, made them all work.

+ Removed redundant 'Plugin' from their names.
+ ImgTeX plugin needed an update.
+ All plugins included in gitit.cabal.
  • Loading branch information...
commit 1a3c23134676aca6ef5de3dea2732111308daf14 1 parent 6ee2aa4
@jgm authored
View
14 gitit.cabal
@@ -42,11 +42,15 @@ data-files: css/screen.css, css/print.css, css/ie.css, css/hk-pyg.css,
data/markupHelp/RST, data/markupHelp/RST+LHS,
data/markupHelp/LaTeX, data/markupHelp/LaTeX+LHS,
data/markupHelp/HTML,
- plugins/CapitalizeEmphasisPlugin.hs,
- plugins/DotPlugin.hs,
- plugins/ImgTexPlugin.hs,
- plugins/InterwikiPlugin.hs,
- plugins/DeprofanizerPlugin.hs
+ plugins/CapitalizeEmphasis.hs,
+ plugins/Dot.hs,
+ plugins/ImgTex.hs,
+ plugins/Interwiki.hs,
+ plugins/Deprofanizer.hs,
+ plugins/WebArchiver.hs,
+ plugins/PageFormat.hs,
+ plugins/ShowUser.hs,
+ plugins/Signature.hs,
CHANGES, README.markdown, YUI-LICENSE, BLUETRIP-LICENSE, TANGOICONS
Flag plugins
View
2  gitit.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE Rank2Types, FlexibleContexts #-}
{-
Copyright (C) 2008 John MacFarlane <jgm@berkeley.edu>
@@ -75,4 +74,3 @@ main = do
let serverConf = Conf { validator = Nothing, port = portNumber conf' }
-- start the server
simpleHTTP serverConf $ wikiHandler conf'
-
View
2  plugins/CapitalizeEmphasisPlugin.hs → plugins/CapitalizeEmphasis.hs
@@ -1,4 +1,4 @@
-module CapitalizeEmphasisPlugin (plugin) where
+module CapitalizeEmphasis (plugin) where
-- This plugin converts emphasized text to ALL CAPS.
-- Not a very useful feature, but useful as an example
View
3  plugins/DeprofanizerPlugin.hs → plugins/Deprofanizer.hs
@@ -1,5 +1,4 @@
--- DeprofanizerPlugin.hs
-module DeprofanizerPlugin (plugin) where
+module Deprofanizer (plugin) where
-- This plugin replaces profane words with "XXXXX".
View
15 plugins/DotPlugin.hs → plugins/Dot.hs
@@ -1,4 +1,4 @@
-module DotPlugin (plugin) where
+module Dot (plugin) where
-- This plugin allows you to include a graphviz dot diagram
-- in a page like this:
@@ -31,14 +31,15 @@ transformBlock (CodeBlock (_, classes, namevals) contents) | "dot" `elem` classe
let (name, outfile) = case lookup "name" namevals of
Just fn -> ([Str fn], fn ++ ".png")
Nothing -> ([], uniqueName contents ++ ".png")
- (ec, out, err) <- liftIO $ readProcessWithExitCode "dot" ["-Tpng"] contents
- if ec == ExitSuccess
- then do
- liftIO $ writeFile (staticDir cfg </> "img" </> outfile) out
- return $ Para [Image name ("/_static/img" </> outfile, "")]
- else error $ "dot returned an error status: " ++ err
+ liftIO $ do
+ (ec, out, err) <- readProcessWithExitCode "dot" ["-Tpng"] contents
+ if ec == ExitSuccess
+ then writeFile (staticDir cfg </> "img" </> outfile) out
+ else error $ "dot returned an error status: " ++ err
+ return $ Para [Image name ("/_static/img" </> outfile, "")]
transformBlock x = return x
-- | Generate a unique filename given the file's contents.
uniqueName :: String -> String
uniqueName = showDigest . sha1 . fromString
+
View
38 plugins/ImgTexPlugin.hs → plugins/ImgTex.hs
@@ -1,4 +1,4 @@
-module ImgTexPlugin (plugin) where
+module ImgTex (plugin) where
{-
This plugin provides a clear math LaTeX output.
@@ -21,12 +21,14 @@ like this:
License: GPL
written by Kohei OZAKI <i@smly.org>
+modified by John MacFarlane to use withTempDir
-}
import Network.Gitit.Interface
import Text.Pandoc.Shared
import System.Process (system)
+import System.Exit
import System.Directory
import Data.Char (ord)
import Data.ByteString.Lazy.UTF8 (fromString)
@@ -37,8 +39,6 @@ import Control.Monad.Trans (liftIO)
plugin :: Plugin
plugin = mkPageTransformM transformBlock
-tmpdir = "/var/tmp/"
-
templateHeader =
( "\\documentclass[12pt]{article}\n"
++ "\\usepackage{amsmath,amssymb,bm}\n"
@@ -53,35 +53,23 @@ templateFooter =
++ "\\end{document}\n"
)
-transformBlock :: Block -> Web Block
+transformBlock :: Block -> PluginM Block
transformBlock (CodeBlock (id, classes, namevals) contents)
| "dvipng" `elem` classes = do
- cfg <- getConfig
+ cfg <- askConfig
let (name, outfile) = case lookup "name" namevals of
Just fn -> ([Str fn], fn ++ ".png")
Nothing -> ([], uniqueName contents ++ ".png")
- liftIO $ do
- curr <- getCurrentDirectory
- initTempDir outfile
- writeFile (outfile++".tex") (templateHeader ++ contents ++ templateFooter)
- system $ "latex " ++ (outfile++".tex") ++ " > /dev/null"
+ curr <- liftIO getCurrentDirectory
+ liftIO $ withTempDir "gitit-imgtex" $ \tmpdir -> do
+ setCurrentDirectory tmpdir
+ writeFile (outfile ++ ".tex") (templateHeader ++ contents ++ templateFooter)
+ system $ "latex " ++ outfile ++ ".tex > /dev/null"
setCurrentDirectory curr
- system $ "dvipng -T tight -bd 1000 -freetype0 -Q 5 --gamma 1.3 "
- ++ tmpdir ++ "gitit-tmp-" ++ outfile ++ "/" ++ outfile ++ ".dvi"
- ++ " -o " ++ (staticDir cfg </> "img" </> outfile)
- ++ " > /dev/null"
- finishTempDir outfile
- return $ Para [Image name ("/img" </> outfile, "")]
+ system $ "dvipng -T tight -bd 1000 -freetype0 -Q 5 --gamma 1.3 " ++
+ (tmpdir </> outfile <.> "dvi") ++ " -o " ++ (staticDir cfg </> "img" </> outfile)
+ return $ Para [Image name ("/_static/img" </> outfile, "")]
transformBlock x = return x
-mkTempDirName :: String -> String
-mkTempDirName = \s -> tmpdir ++ "gitit-tmp-" ++ s
-
-initTempDir :: String -> IO ()
-initTempDir = (\f -> createDirectory f >> setCurrentDirectory f) . mkTempDirName
-
-finishTempDir :: String -> IO ()
-finishTempDir = removeDirectoryRecursive . mkTempDirName
-
uniqueName :: String -> String
uniqueName = showDigest . sha1 . fromString
View
2  plugins/InterwikiPlugin.hs → plugins/Interwiki.hs
@@ -15,7 +15,7 @@
(Written by Gwern Branwen; put in public domain, 2009) -}
-module InterwikiPlugin (plugin) where
+module Interwiki (plugin) where
import Network.Gitit.Interface
View
2  plugins/PageFormatPlugin.hs → plugins/PageFormat.hs
@@ -1,4 +1,4 @@
-module PageFormatPlugin (plugin) where
+module PageFormat (plugin) where
-- This plugin looks at the first line of the stored file.
-- If it is '.. rst', the page is rendered as RST.
View
2  plugins/ShowUserPlugin.hs → plugins/ShowUser.hs
@@ -1,4 +1,4 @@
-module ShowUserPlugin (plugin) where
+module ShowUser (plugin) where
-- This plugin replaces $USER$ with the name of the currently logged in
-- user, or the empty string if no one is logged in.
View
2  plugins/SignaturePlugin.hs → plugins/Signature.hs
@@ -1,4 +1,4 @@
-module SignaturePlugin (plugin) where
+module Signature (plugin) where
-- This plugin replaces $SIG$ with the username and timestamp
-- of the last edit, prior to saving the page in the repository.
View
43 plugins/WebArchiver.hs
@@ -0,0 +1,43 @@
+-- | Scans page of Markdown looking for http links. When it finds them, it submits them
+-- to webcitation.org / https://secure.wikimedia.org/wikipedia/en/wiki/WebCite
+--
+-- Limitations:
+-- * Only parses Markdown, not ReST or any other format; this is because 'readMarkdown'
+-- is hardwired into it.
+--
+-- By: Gwern Branwen; placed in the public domain
+
+module WebArchiver (plugin) where
+
+import Network.Gitit.Interface (askUser, liftIO, processWithM, uEmail, Plugin(PreCommitTransform), Inline(Link))
+import Control.Monad (when)
+import Network.URI (isURI)
+import Control.Concurrent (forkIO)
+import Network.HTTP (getRequest, simpleHTTP)
+import Text.Pandoc (defaultParserState, readMarkdown)
+import Control.Monad.Trans (MonadIO)
+
+plugin :: Plugin
+plugin = PreCommitTransform archivePage
+
+-- archivePage :: (MonadIO m) => String -> ReaderT (Config, Maybe User) (StateT IO) String
+archivePage x = do mbUser <- askUser
+ let email = case mbUser of
+ Nothing -> "nobody@mailinator.com"
+ Just u -> uEmail u
+ let p = readMarkdown defaultParserState x
+ -- force evaluation and archiving side-effects
+ _p' <- liftIO $ processWithM (archiveLinks email) p
+ return x -- note: this is read-only - don't actually change page!
+
+archiveLinks :: String -> Inline -> IO Inline
+archiveLinks e x@(Link _ (uln, _)) = checkArchive e uln >> return x
+archiveLinks _ x = return x
+
+-- | Error check the URL.
+checkArchive :: (MonadIO m) => String -> String -> m ()
+checkArchive e u = when (isURI u) (liftIO $ archiveURL e u)
+
+archiveURL :: String -> String -> IO ()
+archiveURL eml url = forkIO (openURL ("http://www.webcitation.org/archive?url=" ++ url ++ "&email=" ++ eml) >> return ()) >> return ()
+ where openURL = simpleHTTP . getRequest
Please sign in to comment.
Something went wrong with that request. Please try again.