diff --git a/emanote/src/Emanote.hs b/emanote/src/Emanote.hs index 440467b89..22fdceccd 100644 --- a/emanote/src/Emanote.hs +++ b/emanote/src/Emanote.hs @@ -44,6 +44,7 @@ import Emanote.View.Tailwind (compileTailwindCss, generatedCssFile) import Emanote.View.Template qualified as View import Optics.Core ((.~), (^.)) import Relude +import Skylighting (defaultSyntaxMap) import System.FilePath (()) import UnliftIO.Async (race_) @@ -73,6 +74,7 @@ defaultEmanoteConfig cli = , _emanoteConfigNoteFn = id , _emanoteConfigPandocRenderers = defaultEmanotePandocRenderers , _emanoteCompileTailwind = False + , _emanoteSyntaxMap = defaultSyntaxMap } run :: EmanoteConfig -> IO () diff --git a/emanote/src/Emanote/Model/Type.hs b/emanote/src/Emanote/Model/Type.hs index c6f631743..5913bbc36 100644 --- a/emanote/src/Emanote/Model/Type.hs +++ b/emanote/src/Emanote/Model/Type.hs @@ -45,6 +45,7 @@ import Optics.Core (Prism') import Optics.Operators ((%~), (.~), (^.)) import Optics.TH (makeLenses) import Relude +import Skylighting.Types (SyntaxMap) import Text.Pandoc.Scripting (ScriptingEngine) data Status = Status_Loading | Status_Ready @@ -56,6 +57,7 @@ data ModelT encF = Model , _modelEmaCLIAction :: Ema.CLI.Action , _modelRoutePrism :: encF (Prism' FilePath SiteRoute) , _modelPandocRenderers :: EmanotePandocRenderers Model LMLRoute + , _modelSyntaxMap :: SyntaxMap -- ^ Dictates how exactly to render `Pandoc` to Heist nodes. , _modelScriptingEngine :: ScriptingEngine , _modelCompileTailwind :: Bool @@ -120,8 +122,8 @@ modelPluginBaseDir :: ModelT f -> [FilePath] modelPluginBaseDir m = fst . locPath <$> Set.toAscList (m ^. modelLayers) -emptyModel :: Set Loc -> Ema.CLI.Action -> EmanotePandocRenderers Model LMLRoute -> ScriptingEngine -> Bool -> Bool -> UUID -> Stork.IndexVar -> ModelEma -emptyModel layers act ren scriptingEngine ctw allowBrokenLua instanceId storkVar = +emptyModel :: Set Loc -> Ema.CLI.Action -> EmanotePandocRenderers Model LMLRoute -> ScriptingEngine -> Bool -> Bool -> SyntaxMap -> UUID -> Stork.IndexVar -> ModelEma +emptyModel layers act ren scriptingEngine ctw allowBrokenLua syntaxMap instanceId storkVar = Model { _modelStatus = Status_Loading , _modelLayers = layers @@ -130,6 +132,7 @@ emptyModel layers act ren scriptingEngine ctw allowBrokenLua instanceId storkVar , _modelPandocRenderers = ren , _modelScriptingEngine = scriptingEngine , _modelCompileTailwind = ctw + , _modelSyntaxMap = syntaxMap , _modelAllowBrokenLuaFilters = allowBrokenLua , _modelInstanceID = instanceId , -- Inject a placeholder `index.md` to account for the use case of emanote diff --git a/emanote/src/Emanote/Pandoc/Renderer.hs b/emanote/src/Emanote/Pandoc/Renderer.hs index 4ad45b608..b69c6e199 100644 --- a/emanote/src/Emanote/Pandoc/Renderer.hs +++ b/emanote/src/Emanote/Pandoc/Renderer.hs @@ -23,6 +23,7 @@ import Heist.Extra.Splices.Pandoc qualified as Splices import Heist.Extra.Splices.Pandoc.Ctx qualified as Splices import Heist.Interpreted qualified as HI import Relude +import Skylighting.Types (SyntaxMap) import Text.Pandoc.Definition qualified as B -- | Custom Heist renderer function for specific Pandoc AST nodes. @@ -48,14 +49,16 @@ mkRenderCtxWithPandocRenderers :: (Monad m) => PandocRenderers model route -> Map Text Text -> + SyntaxMap -> model -> route -> -- | Rendering feature selection (code highlighting, static math, …) Splices.RenderFeatures -> HeistT Identity m Splices.RenderCtx -mkRenderCtxWithPandocRenderers nr classRules model x = +mkRenderCtxWithPandocRenderers nr classRules syntaxMap model x = Splices.mkRenderCtx classRules + syntaxMap (\ctx -> dispatchBlock model nr ctx x) (\ctx -> dispatchInline model nr ctx x) diff --git a/emanote/src/Emanote/Source/Dynamic.hs b/emanote/src/Emanote/Source/Dynamic.hs index ddb6f8f85..9dcd1900b 100644 --- a/emanote/src/Emanote/Source/Dynamic.hs +++ b/emanote/src/Emanote/Source/Dynamic.hs @@ -5,6 +5,7 @@ module Emanote.Source.Dynamic ( emanoteSiteInput, EmanoteConfig (..), emanoteCompileTailwind, + emanoteSyntaxMap, emanoteConfigCli, emanoteConfigNoteFn, emanoteConfigPandocRenderers, @@ -31,6 +32,7 @@ import Emanote.Source.Pattern qualified as Pattern import Optics.TH (makeLenses) import Paths_emanote qualified import Relude +import Skylighting.Types (SyntaxMap) import System.UnionMount qualified as UM import Text.Pandoc.Lua (getEngine) import UnliftIO (MonadUnliftIO) @@ -45,6 +47,7 @@ data EmanoteConfig = EmanoteConfig -- ^ How to render Pandoc to Heist HTML. , _emanoteCompileTailwind :: Bool -- ^ Whether to replace Tailwind2 CDN with a minimized Tailwind3 CSS file. + , _emanoteSyntaxMap :: SyntaxMap } {- | Make an Ema `Dynamic` for the Emanote model. The bulk of logic @@ -70,6 +73,7 @@ emanoteSiteInput cliAct EmanoteConfig {..} = do scriptingEngine _emanoteCompileTailwind (CLI.allowBrokenLuaFilters _emanoteConfigCli) + _emanoteSyntaxMap instanceId storkIndex -- NOTE: Per-layer ignore patterns are loaded once at startup. Edits diff --git a/emanote/src/Emanote/View/Common.hs b/emanote/src/Emanote/View/Common.hs index 7e7aea11d..e15b1e7b6 100644 --- a/emanote/src/Emanote/View/Common.hs +++ b/emanote/src/Emanote/View/Common.hs @@ -96,6 +96,7 @@ mkTemplateRenderCtx model r meta = Renderer.mkRenderCtxWithPandocRenderers pandocRenderers classRules + (model ^. M.modelSyntaxMap) model r renderFeatures