Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Null? #91

Closed
jgm opened this issue Jun 4, 2021 · 8 comments · Fixed by #108
Closed

Remove Null? #91

jgm opened this issue Jun 4, 2021 · 8 comments · Fixed by #108

Comments

@jgm
Copy link
Owner

jgm commented Jun 4, 2021

We have a Block constructor Null. I think this was added before we were using Builder in the readers; I wonder if there's any reason for it to exist. Note that there's nothing like this for Inline.

@jgm jgm closed this as completed in f796401 Oct 1, 2021
jgm added a commit that referenced this issue Oct 13, 2021
This reverts commit f796401.

Reopens #91.

This is premature unless packaged with more significant
API changes, as any API changes cause disruption.
@jgm jgm reopened this Oct 13, 2021
@jgm
Copy link
Owner Author

jgm commented Oct 13, 2021

I decided to wait on this until it can be packaged with other breaking API changes. Otherwise this causes too much disruption for what it gains us.

@nichtich
Copy link

nichtich commented Dec 6, 2021

Null is useful in filters that remove block elements by replacing them with a Null element. Pandoc should not throw an error when a Null element is found in JSON input, but silently ignore it.

@jgm
Copy link
Owner Author

jgm commented Dec 6, 2021

@nichtich I guess there are two potentially separate issues here:

  • should the be a Null constructor in the Haskell type Block?
  • in reading the JSON serialization, what should be done with JSON null elements?

We could, in principle, ignore JSON nulls without having a Null constructor in Block (though there may be issues of detail I'm not thinking of, especially since we're using an automatically derived FromJSON instance).

@jgm
Copy link
Owner Author

jgm commented Dec 6, 2021

Note also that one can always write a filter that is capable of removing Blocks by making the type of the underlying transformation [Block] -> [Block]; in fact I often use a Block -> [Block] and promote it to [Block] -> [Block] using concatMap.

@nichtich
Copy link

nichtich commented Dec 7, 2021

should the be a Null constructor in the Haskell type Block?

No, there is no need to have it.

in reading the JSON serialization, what should be done with JSON null elements?

They can be ignored but should be documented. Right now the JSON format is only described implicitly by Haskell types, so removal would also make existing AST structure invalid. Confusion such as #75 (table format changed two times from 1.20 to 1.21 to 1.22) and any breaking of backwards compatibility should be avoided.

@jgm
Copy link
Owner Author

jgm commented Dec 7, 2021

That's true, explicitly ignoring null in parsing JSON would keep a degree of backwards compatibility for JSON filters that use Null. (As long as they aren't written in Haskell using the Null constructor.) Doing this, however, might cause a lot of additional code complexity if it means not using automatic derivation of the FromJSON instance. In that case it may not be worth it -- and maybe we should just keep Null, as ugly but harmless.

zspitz added a commit to zspitz/PandocFilters that referenced this issue Dec 22, 2021
tarleb pushed a commit to tarleb/pandoc-types that referenced this issue Jan 13, 2023
@jgm jgm closed this as completed in #108 Jan 13, 2023
jgm added a commit that referenced this issue Jan 13, 2023
@zkamvar
Copy link

zkamvar commented Jan 24, 2023

What is the appropriate replacement pattern for using pandoc.Null()? I don't speak enough Lua to understand what this means:

Note also that one can always write a filter that is capable of removing Blocks by making the type of the underlying transformation [Block] -> [Block]; in fact I often use a Block -> [Block] and promote it to [Block] -> [Block] using concatMap.

The solution I've come up with is to replace pandoc.Null() with pandoc.RawBlock("text", "") as in:

::::: removeme

This should disappear

:::::

::::: keep

This should stay

:::::
Div = function(el)
  v,i = el.classes:find("removeme")
  if i ~= nil then
    return pandoc.RawBlock("text", "")
  else
    return el
  end
end

Is this correct?

@jgm
Copy link
Owner Author

jgm commented Jan 24, 2023

In a Lua filter you can return {} and it will just omit the element.

byorgey added a commit to byorgey/BlogLiterately that referenced this issue Feb 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants