Open peterjaap opened 4 years ago
Thanks for sharing your experiences. I read you use a lot of code snippets. I agree that "paste code" could be improved in the way you describe.
On the other hand there is the include-with-tags syntax that allows to includes snippets from a file. That might reduce copy-and-paste of code. Advanced syntax allows you to include multiple snippets, everything expect the snippets, etc.
I've used this syntax in several places when I wrote the documentation in the same repository as the code.
It allowed me to test (even unit-test) the code inside a regular source file and use the snippets inside a document without duplicating it using copy-and-paste. For the included content I've adjusted the indent, see normalize block indent for details.
Please let me know if this would work for you as well.
@ahus1 thanks, I ran into that notation before.
Unfortunately this doesn't work for my use-case; I include source code diffs in my text, not the actual source code. I also clean up the source code for formatting reasons (strip out comments, unused methods, etc).
@peterjaap - I'm trying to reproduce the indent getting lost. I copied some Java code or text file from another file and the indent was still there after I copied it to the AsciiDoc file. Something must be different in my setup compared to yours.
What editor did you copy the contents from, from within the same JetBrains IDE instance? Did you use spaces or tabs?
@peterjaap - please state the version of the IDE and the AsciiDoc plugin you use, maybe this plays a role. You can copy-and-paste the version information of you idea using the following menu entry: go to Help -> About, click on 'Copy to Clipboard' (a small icon to click on appears once you hover the mouse over the logo) and paste the contents of your clipboard here.
@ahus1
PhpStorm 2019.3.3
Build #PS-193.6494.47, built on February 12, 2020
Licensed to elgentos / Peter Jaap Blaakmeer
Subscription is active until June 13, 2020
Runtime version: 11.0.5+10-b520.38 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 5.3.0-40-generic
GC: ParNew, ConcurrentMarkSweep
Memory: 1904M
Cores: 8
Registry: run.processes.with.pty=TRUE, ide.editor.tabs.open.at.the.end=true, debugger.watches.in.variables=false, php.brace.alt.syntax=true
Non-Bundled Plugins: com.jinsihou.react.snippets, com.magento.idea.magento2plugin, com.magicento2.magicento2, com.potterhsu.jsonviewer, de.espend.idea.laravel, de.thomasrosenau.diffplugin, intellij.prettierJS, izhangzhihao.rainbow.brackets, net.seesharpsoft.intellij.plugins.csv, tanvd.grazi, org.asciidoctor.intellij.asciidoc, ru.adelf.idea.dotenv, some.awesome
I was finally able to reproduce the problem locally, and I have a workaround for you while the fix is under way: instead of an open block --
(two minus), please use a source code block ----
(4 minus).
This provides standard syntax highlighting for source code, and also prevents reformatting the text.
When pasting the contents from the clipboard to a source code block, the indent will be preserved. For a source block will be anything withing ----
, the next version will recognize --
with the style source
as source blocks, too.
If you copy contents to a different area, the indent (spaces at the beginning of the line) will still be lost. This is due to the "reformat on paste" option enabled by JetBrains as standard. The behavior can be changed here in the settings "Editor > Smart Keys".
While it's important for compliance (the tool aims to parse AsciiDoc as defined), please note that the use of open blocks for source blocks is generally discouraged and likely to be deprecated at some point.
@ahus1 @mojavelinux thanks for that! I didn't even know there was a difference between --
and ----
, I had just assumed it was at least two dashes, like Markdown does table dividers.
The indenting indeed works correctly when using source code blocks. That leaves the question about inputting a subdirectory in front of the new filename.
Pre-release 0.30.48 is now available that fixes the issue with source style open blocks. The enhancement to support adding folder names will be part of a future release.
Please give it a try and see if it solves your issue. Please note that this pre-release includes several other enhancements and fixes. Please have a look at the change log for the full details. The most recent version also tries to validate xrefs. If you discover corner cases, please report them as new GitHub issues.
The new pre-release of the plugin is available from GitHub releases and the IntelliJ AsciiDoc EAP repository.
@ahus1 the new version does indeed fix the indenting.
Similar to the paste image feature, by using this feature you should be prompted for a file path to which it saves the clipboard contents. It should then include the file into the current file using
include::here/the/filepath.ext[]
.I guess a large portion of the code could be repurposed. Unfortunately, my Java isn't as strong.
Use-case; I'm writing a tech book and I include tons of code examples. I now paste the code into the current file and Alt+Enter to get to the
Extract Include Directive
intention but this has the downside of loosing indentation of the code upon pasting in the adoc. Also, specifying a subdirectory is currently not supported so I have to move the file manually to my code example subdir after it is created.