Skip to content

pre_write extension callbacks cannot modify the rendered HTML #161

Description

@halostatue

I'm working on an extension that parses links like [foo]($ref:foo.md) and turns it into a proper link so that I don't have to know the full rendered path to the post. I'm doing this as part of a pre_write extension with Floki to parse the the <a href= (or <img src=) value and convert $ref:foo.md to the appropriate full path for the post named foo.md.

It doesn't work. I think that the fix is relatively small in lib/mix/tasks/tableau.build.ex:

     token = put_in(token.site[:pages], pages)
     token = mods |> extensions_for(:pre_write) |> run_extensions(:pre_write, token)

-    for %{body: body, permalink: permalink} <- pages do
+    for %{body: body, permalink: permalink} <- token.site[:pages] do
       file_path = build_file_path(out, permalink)
       dir = Path.dirname(file_path)

       File.mkdir_p!(dir)

       File.write!(file_path, body)
    end

As long as the pre_write/1 callback updates token.site[:pages] as part of its flow, it should be able to work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions