-
Notifications
You must be signed in to change notification settings - Fork 338
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
Asciidoctor: Support for "open in widget" #627
Changes from all commits
9a3d04e
b3fa0ec
d5fa2fb
702975e
5c30bbc
85abcf4
b74306c
e272218
cc8f3c7
1624996
0937803
5fe67cc
15ba6d2
922f3ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,14 +23,62 @@ | |
# <1> The count of categories that were matched | ||
# <2> The categories retrieved | ||
# | ||
# Turns | ||
# [source,js] | ||
# -------------------------------------------------- | ||
# GET / <1> | ||
# -------------------------------------------------- | ||
# pass:[// CONSOLE] | ||
# <1> The count of categories that were matched | ||
# <2> The categories retrieved | ||
# | ||
# Into | ||
# [source,console] | ||
# -------------------------------------------------- | ||
# GET / <1> | ||
# -------------------------------------------------- | ||
# <1> The count of categories that were matched | ||
# <2> The categories retrieved | ||
# | ||
class ElasticCompatTreeProcessor < TreeProcessorScaffold | ||
include Asciidoctor::Logging | ||
|
||
def process_block(block) | ||
if block.context == :listing && block.style == "source" && | ||
block.subs.include?(:specialcharacters) == false | ||
# callouts have to come *after* special characters | ||
had_callouts = block.subs.delete(:callouts) | ||
block.subs << :specialcharacters | ||
block.subs << :callouts if had_callouts | ||
end | ||
return unless block.context == :listing && block.style == 'source' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a minor Ruby style thing, but I would typically only use if block.context == :listing && block.style == 'source'
process_subs block
process_lang_override block
end |
||
|
||
process_subs block | ||
process_lang_override block | ||
end | ||
|
||
def process_subs(block) | ||
return if block.subs.include? :specialcharacters | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing here. I would write this like: if !block.subs.include? :specialcharacters
# callouts have to come *after* special characters
had_callouts = block.subs.delete(:callouts)
block.subs << :specialcharacters
block.subs << :callouts if had_callouts
end |
||
|
||
# callouts have to come *after* special characters | ||
had_callouts = block.subs.delete(:callouts) | ||
block.subs << :specialcharacters | ||
block.subs << :callouts if had_callouts | ||
end | ||
|
||
LANG_MAPPING = { | ||
'AUTOSENSE' => 'sense', | ||
'CONSOLE' => 'console', | ||
'KIBANA' => 'kibana', | ||
'SENSE' => 'sense', | ||
}.freeze | ||
|
||
def process_lang_override(block) | ||
next_block = block.next_adjacent_block | ||
return unless next_block && next_block.context == :paragraph | ||
return unless next_block.source =~ %r{pass:\[//\s*([^:\]]+)(?::\s*([^\]]+))?\]} | ||
|
||
lang = LANG_MAPPING[$1] | ||
snippet = $2 | ||
return unless lang # Not a language we handle | ||
|
||
block.set_attr 'language', lang | ||
block.set_attr 'snippet', snippet | ||
|
||
block.parent.blocks.delete next_block | ||
block.parent.reindex_sections | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be more readable if all the logic was in one place. The same things I said above about def process_lang_override(block)
next_block = block.next_adjacent_block
unless next_block && next_block.context == :paragraph &&
next_block.source =~ %r{pass:\[//\s*([^:\]]+)(?::\s*([^\]]+))?\]} &&
lang = LANG_MAPPING[$1]
snippet = $2
block.set_attr 'language', lang
block.set_attr 'snippet', snippet
block.parent.blocks.delete next_block
block.parent.reindex_sections
end
end |
||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've dropped the docs for this because I think, at least as we have it now, it is super confusing. It isn't compatible with Elasticsearch's tests or
COPY AS cURL
and I expect it is pretty surprising in general.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason these custom blocks exist is for the Definitive Guide, where we wanted to display a small amount of JSON but then click through to console to show the full example, including setup etc. Other than the Def Guide, it is not really used anywhere else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah! I tracked that down.
We've talked on and off about having some way of hiding something like these custom blocks but in a way with visual feedback for what you are getting. I'm not sure the right way to do it but I could image these making a comeback eventually.
But as I have it now I'm just dropping the docs for them because I don't want people using them without really knowing what they are doing.