By | Chris Done |
At | 2011-07-09 |
Title | Add line numbers. |
Description |
Edit file src/Amelie/View/Highlight.hs 33188 → 33188
7 7 module Amelie.View.Highlight
8 8 (highlightPaste
9 9 ,highlightHaskell)
10 10 where
11 11 - 12 import Amelie.Types
- 13 import Amelie.View.Html
+ 12 import Amelie.Types
+ 13 import Amelie.View.Html
14 14 - 15 import Data.List (find)
- 16 import Data.Text (Text,unpack)
- 17 import Language.Haskell.HsColour.CSS (hscolour)
- 18 import Prelude hiding ((++))
- 19 import Text.Blaze.Html5 as H hiding (map)
+ 15 import Control.Monad
+ 16 import Data.List (find)
+ 17 import Data.Monoid.Operator
+ 18 import Data.Text (Text,unpack,pack)
+ 19 import qualified Data.Text as T
+ 20 import Language.Haskell.HsColour.CSS (hscolour)
+ 21 import Prelude hiding ((++))
+ 22 import Text.Blaze.Html5 as H hiding (map)
+ 23 import qualified Text.Blaze.Html5.Attributes as A
20 24 21 25 -- | Syntax highlight the paste.
22 26 highlightPaste :: [Language] -> Paste -> Html
23 27 highlightPaste langs Paste{..} =
- 24 H.table ! aClass "code" $
+ 28 H.table ! aClass "code" $ do
+ 29 td ! aClass "line-nums" $ do
+ 30 pre $
+ 31 forM_ [1..length (T.lines pastePaste)] $ \i -> do
+ 32 let name = "line" ++ pack (show i)
+ 33 href ("#" ++ name) (toHtml i) ! A.id (toValue name) ! A.name (toValue name)
+ 34 "\n"
25 35 td $
26 36 case lang of
27 37 Just (Language{languageName="haskell"}) ->
28 38 preEscapedString $ hscolour False (unpack pastePaste)
29 39 _ -> pre $ toHtml pastePaste
… … … … Edit file src/Amelie/View/Style.hs 33188 → 33188
178 178 classRule "steps" $ do
179 179 marginTop "1em"
180 180 classRule "steps-expr" $ do
181 181 rule ".text" $ do
182 182 width "300px"
+ 183 183 184 classRule "code" $ do
184 185 tokens
- 185 lineNumbers
186 186 187 187 rule "pre" $ do
188 188 margin "0"
189 189 190 190 rule "td" $ do
191 191 verticalAlign "top"
- 192 + 192 lineNumbers
+ 193 193 194 -- | Style for diff groups.
194 195 diff :: CSS Rule
195 196 diff = do
196 197 classRule "diff-both" $
197 198 return ()
… … … … 238 239 where token name props = rule (".hs-" ++ name) $ props
239 240 tokenColor name col = token name $ color col
240 241 jcolor name col = rule ("." ++ name) $ color col
241 242 242 243 -- | The line number part.
- 243 lineNumbers :: CSS (Either Property Rule)
+ 244 lineNumbers :: CSS Rule
244 245 lineNumbers = do
- 245 rule ".linenodiv" $ do
+ 246 rule ".amelie-line-nums pre" $ do
246 247 margin "0 1em 0 0"
247 248 textAlign "right"
- 248 249 249 rule "a" $ do
250 250 textDecoration "none"
251 251 color "#555"
+ 252 rule "a:target" $ do
+ 253 textDecoration "underline"
+ 254 color "#000"
252 255 253 256 -- | Home page styles.
254 257 home :: CSS Rule
255 258 home = do
256 259 rule "#new" wrap
… … … …