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

Fixes #39. Spaces and source-language name for language attribute #40

Merged
merged 5 commits into from
Aug 3, 2023

Conversation

TobiasZawada
Copy link
Collaborator

The asciidoctor manual accepts spaces at the beginning of the language attribute of code blocks. Furthermore, the language attribute can also be a named attribute source-language.

So

[source,emacs-lisp]
----
	(message "Hello world")
----

is the same as

[source, emacs-lisp]
----
	(message "Hello world")
----

and as

[source, source-language = emacs-lisp]
----
	(message "Hello world")
----

Only the first version is fontified as emacs-lisp in origin/master at commit b0702bdeb8d799720661766936c36ec3b454c609.

adoc-mode.el Outdated
@@ -2033,7 +2033,7 @@ START-SRC and END-SRC delimit the actual source code."
(outer-brackets-and-delimiter (&rest stuff)
(format "^\\[%s\\]\n\\(?2:----+\\)\n"
(apply #'concat stuff)))
(lang () ",\\(?1:[^],]+\\)")
(lang () ",[\t ]*\\(source-language[\t ]*=[\t ]*\\)?\\(?1:[^],]+\\)")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add here some comments with the snippets from the manual, so it's clear what we're matching against. Ideally we should also have some matching unit tests, but this can be done later.

Copy link
Collaborator Author

@TobiasZawada TobiasZawada Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review.
The asciidoctor manual is not clear about the 2nd code block attribute. So I had a look at the Ruby code. There I misinterpreted the document attribute source-language as block attribute. I corrected this with the last commit.

Copy link
Collaborator Author

@TobiasZawada TobiasZawada Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the source-style is applicable to any fenced block.
At the end of the following page they use it with the open block (which is very general): https://docs.asciidoctor.org/asciidoc/latest/blocks/open-blocks/

So maybe, we should take a more general approach and just test the style of each block.
Maybe, even asciidoc-Formatters still work in source blocks whose style is not listing or literal.

We can think about this later.
The changes in this branch/pull-request are nevertheless an improvement.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rabbit-hole is quite deep: asciidoctor/asciidoctor-pdf#180

Copy link
Collaborator Author

@TobiasZawada TobiasZawada Aug 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bbatsov ... and even deeper ...

:source-highlighter: pygments
:myBlock: source,ruby,subs="verbatim,quotes"

[{myBlock}]
----
class SomeClass
  for i in 1..5 do
      "Hello *world*".print
  end
----

:saveOldBlock: {myBlock}
:myBlock: source,python,subs="verbatim,quotes"

[{myBlock}]
----
class AnotherClass
  for i in 1..5 do
      "Hello *world*".print
  end
----

:myBlock: {saveOldBlock}
[{myBlock}]
----
class BehindTheLocalDef
  for i in 1..5 do
      "Hello *world*".print
  end
----

Attribute substitutions are carried out in attribute lists before parsing: https://docs.asciidoctor.org/asciidoc/latest/attributes/positional-and-named-attributes/#attribute-list-parsing

@TobiasZawada TobiasZawada force-pushed the SrcBlock/SpacesInAttributeLists branch from 73af600 to 9cb822d Compare August 1, 2023 22:08
Tobias Zawada added 5 commits August 4, 2023 01:02
Also ignore whitespace at the end of the block attribute line.
Add ert tests for
- literal code blocks (....)
- ignored whitespace after leading comma of 2nd attribute and at end of attr line
@TobiasZawada TobiasZawada force-pushed the SrcBlock/SpacesInAttributeLists branch from 9cb822d to 4e7032e Compare August 3, 2023 23:24
@TobiasZawada
Copy link
Collaborator Author

@bbatsov As we have seen, the rabbit hole is quite deep.
Let us accept these changes for now that at least those source blocks are highlighted that we have discovered in the spec so far, i.e., listings, open blocks and literal blocks.

@TobiasZawada TobiasZawada merged commit 26d189e into master Aug 3, 2023
8 checks passed
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 this pull request may close these issues.

2 participants