znai
znai copied to clipboard
How to create anchor for div, tables, etc.?
We can create link from header, but in my case, I have use intensive linking in page using paragraphs, images, table. Can you create some plugin for creation anchor?
<div id="some-unique-id" ...
<img id="some-unique-id" ...
<table id="some-unique-id" ...
what do you think about an idea of adding anchors to tiles of code snippets/images/tables? something like
```cpp {title: "my snippet", anchorId: "my-snippet"}
...
```
or
```cpp {title: "my snippet", anchor: true}
...
```
and then anchor id will be generated from title
Both variants are good. First example for migration to Znai, all anchors already exists. Second example for writing new content and not needed thinking what name anchor is used. If choose only one - first more preferable.
Thank you I released patch yesterday to fix some regressions and add small features. this feature will go into a next release that may take a few weeks. do you by any chance have a way to build znai locally? This way you may get access to the features sooner. also need to consider to set auto snapshot build from master. But not sure how easy it is.
Sure. I use Linux. Only need instruction.
just added https://testingisdocumenting.org/znai/znai-development/local-build let me know if things are missing and feel free to PR if you want
Hello
Unfortunately, build is failure
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project znai-utils: There are test failures.
If I run without test:
$ mvn clean install -DskipTests
Output
BUILD SUCCESS
But file znai-dist/target/dist-znai.zip doesn't exist.
Any chance you can provide more info on the failed test? Did you install graphviz to be in your PATH?
I installed graphviz. Command dot in my PATH, test work fine:
$ sudo apt install graphviz
$ which dot
/usr/bin/dot
$ echo 'digraph { a -> b }' | dot -Tsvg > output.svg
Maven test error output:
...
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.testingisdocumenting.znai.utils.StringUtilsTest
. [value] equals "
statement1;
statement2"
[value]: actual: <java.lang.String>
_______________
statement1;
statement2
_______________
expected: <java.lang.String>
_______________
statement1;
statement2
_______________ (58ms)
. [value] equals ""
[value]: actual: "" <java.lang.String>
expected: "" <java.lang.String> (0ms)
. [value] equals 8
[value]: actual: 8 <java.lang.Integer>
expected: 8 <java.lang.Integer> (1ms)
. [value] equals true
[value]: actual: true <java.lang.Boolean>
expected: true <java.lang.Boolean> (1ms)
X failed expecting [value] to equal true:
mismatches:
[value]: actual: false <java.lang.Boolean>
expected: true <java.lang.Boolean> (4ms)
. [value] equals "a prefix:line1 line1
line2
line #3"
[value]: actual: <java.lang.String>
____________________
a prefix:line1 line1
line2
line #3
____________________
expected: <java.lang.String>
____________________
a prefix:line1 line1
line2
line #3
____________________ (1ms)
. [value] equals "int a = 2;
int b = 3;"
[value]: actual: <java.lang.String>
__________
int a = 2;
int b = 3;
__________
expected: <java.lang.String>
__________
int a = 2;
int b = 3;
__________ (1ms)
. [value] equals ""
[value]: actual: "" <java.lang.String>
expected: "" <java.lang.String> (1ms)
. [value] equals "20"
[value]: actual: "20" <java.lang.String>
expected: "20" <java.lang.String> (0ms)
. [value] equals "hello"
[value]: actual: "hello" <java.lang.String>
expected: "hello" <java.lang.String> (1ms)
. [value] equals ""
[value]: actual: "" <java.lang.String>
expected: "" <java.lang.String> (0ms)
. [value] equals ""
[value]: actual: "" <java.lang.String>
expected: "" <java.lang.String> (0ms)
. [value] equals "hello world"
[value]: actual: "hello world" <java.lang.String>
expected: "hello world" <java.lang.String> (1ms)
. [value] equals "hello world"
[value]: actual: "hello world" <java.lang.String>
expected: "hello world" <java.lang.String> (0ms)
. [value] equals """"
[value]: actual: """" <java.lang.String>
expected: """" <java.lang.String> (0ms)
. [value] equals ""hello world""
[value]: actual: ""hello world"" <java.lang.String>
expected: ""hello world"" <java.lang.String> (1ms)
. [value] equals "hello "
[value]: actual: "hello " <java.lang.String>
expected: "hello " <java.lang.String> (1ms)
Tests run: 9, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.965 sec <<< FAILURE!
is number(org.testingisdocumenting.znai.utils.StringUtilsTest) Time elapsed: 0.031 sec <<< FAILURE!
java.lang.AssertionError:
mismatches:
[value]: actual: false <java.lang.Boolean>
expected: true <java.lang.Boolean>
at org.testingisdocumenting.webtau.expectation.ActualValue.handleMismatch(ActualValue.java:135)
at org.testingisdocumenting.webtau.expectation.ActualValue.shouldStep(ActualValue.java:89)
at org.testingisdocumenting.webtau.expectation.ActualValue.lambda$should$0(ActualValue.java:55)
at org.testingisdocumenting.webtau.utils.FunctionUtils.lambda$toSupplier$0(FunctionUtils.java:26)
at org.testingisdocumenting.webtau.utils.FunctionUtils.lambda$toFunction$3(FunctionUtils.java:46)
at org.testingisdocumenting.webtau.reporter.WebTauStep.executeSingleRunWithAction(WebTauStep.java:302)
at org.testingisdocumenting.webtau.reporter.WebTauStep.executeSingleRun(WebTauStep.java:290)
at org.testingisdocumenting.webtau.reporter.WebTauStep.execute(WebTauStep.java:283)
at org.testingisdocumenting.webtau.expectation.ActualValue.executeStep(ActualValue.java:178)
at org.testingisdocumenting.webtau.expectation.ActualValue.should(ActualValue.java:53)
at org.testingisdocumenting.webtau.expectation.ActualValueExpectations$should.call(Unknown Source)
at org.testingisdocumenting.webtau.data.expectation.ExpectationExtension.should(ExpectationExtension.groovy:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:54)
at org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod.invoke(NewInstanceMetaMethod.java:54)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:247)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
at org.testingisdocumenting.znai.utils.StringUtilsTest.is number(StringUtilsTest.groovy:89)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
...
I'm setting java in terminal like this (use 8.0.342-amzn in current terminal):
$ sdk use java 8.0.342-amzn
Thank you for looking into it. Really appreciate it. Will dig into it a bit later.
@baobab-it this was released for tables, images, snippets https://testingisdocumenting.org/znai/snippets/external-code-snippets#anchor
I was trying out and got error:
Execution default-cli of goal org.testingisdocumenting.znai:znai-maven-plugin:1.60:build failed: can't find the anchor #content-id
Link work properly after page was generation, but parser doesn't see anchor during parsing page.
This is mean, when I paste the copied link into the page:
[snippets](#content-id)
I got error.
Could you provide more details? Like what you have put on the page?
Sure
Simple project structure:
├── pom.xml
└── znai
├── HelloWorldApp.java
├── index.md
├── lookup-paths
├── meta.json
└── toc
znai/HelloWorldApp.java:
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
znai/index.md:
# Title
:include-java: HelloWorldApp.java {
autoTitle: true,
anchorId: "unique-anchor-id"
}
[link to snippets of code](#unique-anchor-id)
Build:
$ mvn znai:build
Got error:
...
[ERROR] Failed to execute goal org.testingisdocumenting.znai:znai-maven-plugin:1.60:build (default-cli) on project doc: Execution default-cli of goal org.testingisdocumenting.znai:znai-maven-plugin:1.60:build failed: can't find the anchor #unique-anchor-id
[ERROR] check file: project/znai/index.md, section title: Title
...
Thank you. Appreciate it!
@baobab-it could you please check what maven plugin version do you use? I can't seem to reproduce
Latest version:
<plugin>
<groupId>org.testingisdocumenting.znai</groupId>
<artifactId>znai-maven-plugin</artifactId>
<version>1.60</version>
<configuration>
<docId>docs</docId>
<deployRoot>dist</deployRoot>
</configuration>
</plugin>
thanks, just spotted version in the error output 🤦
looks like the problem is include-java vs include-file. Could you please confirm that include-file works?
Yes, include-file allow compiling, but link working wrong
Must be
http://localhost:8000/docs/#unique-anchor-id
Got (after page refresh page 404)
http://localhost:8000/docs//index#unique-anchor-id
In root index page, need remove /index from link
Yeah spotted this as well. Bug related to index html. PR is building. Most likely will do a patch release next week. Thanks for trying and reporting the issues.