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

Get line number of element being filtered in Lua filters #5907

Closed
mitinarseny opened this issue Nov 14, 2019 · 1 comment
Closed

Get line number of element being filtered in Lua filters #5907

mitinarseny opened this issue Nov 14, 2019 · 1 comment

Comments

@mitinarseny
Copy link

mitinarseny commented Nov 14, 2019

It's a feature request to provide opportunity to get the line number of element that is being filtered with Lua filters. It would be useful to have sourceLineNumber field in each element inside pandoc's AST as if you want to throw an error while applying filter, it's hard to guess where is the block which caused an error. Of course, It can be done by assigning id to every block that you write:

```{#errorBlock filterAttr="unsupported"}
something here
```

And in the filter:

function CodeBlock(block)
  if block.attributes['filterAttr'] ~= 'supported' then
    error('An error while processing block'
      .. ((block.identifier ~= '' and (' #' .. block.identifier)) or '')
      .. ': unsupported \'filterAttr\' value \'' .. block.attributes['filterAttr'] .. '\'')
  end
  -- something here with filterAttr
end

That would give an error:

An error while processing block #errorBlock: unsupported 'filterAttr' value 'unsupported'

But what if end user do not want to give each block an id?

Moreover, it would be even better if i can leave it to pandoc and just throw an error:

function CodeBlock(block)
  if block.attributes['filterAttr'] ~= 'supported' then
    error('unsupported \'filterAttr\' value \'' .. block.attributes['filterAttr'] .. '\'')
  end
  -- something here with filterAttr
end

And pandoc would handle errors and write id of element and line number when element starts:

An error while processing CodeBlock #errorBlock on line 1: unsupported 'filterAttr' value 'unsupported'

Or if id is empty:

An error while processing CodeBlock on line 1: unsupported 'filterAttr' value 'unsupported'
@tarleb
Copy link
Collaborator

tarleb commented Nov 14, 2019

Line numbers in elements are the central part of #4565, so I'm closing in favor of that issue.

Error messages could certainly be improved in general. Would you open a new issue for that?

@tarleb tarleb closed this as completed Nov 14, 2019
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

No branches or pull requests

2 participants