Skip to content

Commit

Permalink
Enable markdown for content, header and label in annotation point
Browse files Browse the repository at this point in the history
* enable markdown formating for content in annotate point

* add slot for header and label in annotation point

* add documentation on using markdown in content label and header

* add functional test

* add test cases for annotation
  • Loading branch information
yucheng11122017 authored Feb 24, 2024
1 parent 31d00dc commit 58fbbd0
Show file tree
Hide file tree
Showing 11 changed files with 761 additions and 41 deletions.
17 changes: 17 additions & 0 deletions docs/userGuide/syntax/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ The x and y coordinates of each Annotate Point are relative to the image and are
</variable>
</include>

**Use markdown in the header, label and content**

Annotate Points supports markdown in the header, label and content.

<include src="codeAndOutput.md" boilerplate >
<variable name="highlightStyle">html</variable>
<variable name="code">

<annotate src="../../images/annotateSampleImage.png" width="500" alt="Sample Image">
<a-point x="25%" y="25%" content="# Content" />
<a-point x="50%" y="25%" header=":blush:" />
<a-point x="75%" y="25%" label=":heart:"/>
</annotate>
</variable>
</include>


**Customising shapes for Annotate Point** <br>

Annotate Points supports different shapes and customisation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@
{
"src": "testAnnotate.md",
"title": "Annotate Feature Test",
"headings": {},
"headings": {
"content": "Content"
},
"headingKeywords": {}
},
{
Expand Down
176 changes: 144 additions & 32 deletions packages/cli/test/functional/test_site/expected/testAnnotate.html
Original file line number Diff line number Diff line change
Expand Up @@ -208,63 +208,175 @@ <h3 id="testing-site-nav">Testing Site-Nav<a class="fa fa-anchor" href="#testing
<breadcrumb></breadcrumb>
<p><strong>Annotate with saved Image</strong></p>
<annotate src="./images/annotateSampleImage.png" width="500" alt="sampleImage">
<a-point x="25%" y="25%" content="Lorem ipsum dolor sit amet"></a-point>
<a-point x="25%" y="25%"><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
</annotate>
<br>
<p><strong>Annotate point positions</strong></p>

<annotate src="./images/annotateSampleImage.png" width="350" alt="sampleImage">
<a-point x="0%" y="0%" content="Lorem ipsum dolor sit amet"></a-point>
<a-point x="50%" y="50%" content="Lorem ipsum dolor sit amet"></a-point>
<a-point x="100%" y="100%" content="Lorem ipsum dolor sit amet"></a-point>
<a-point x="0%" y="0%"><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
<a-point x="50%" y="50%"><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
<a-point x="100%" y="100%"><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
</annotate>

<annotate src="./images/annotateSampleImage.png" width="600" alt="sampleImage">
<a-point x="0%" y="0%" content="Lorem ipsum dolor sit amet"></a-point>
<a-point x="50%" y="50%" content="Lorem ipsum dolor sit amet"></a-point>
<a-point x="100%" y="100%" content="Lorem ipsum dolor sit amet"></a-point>
<a-point x="0%" y="0%"><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
<a-point x="50%" y="50%"><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
<a-point x="100%" y="100%"><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
</annotate>

<annotate src="./images/annotateSampleImage.png" width="1500" alt="sampleImage">
<a-point x="0%" y="0%" content="Lorem ipsum dolor sit amet"></a-point>
<a-point x="50%" y="50%" content="Lorem ipsum dolor sit amet"></a-point>
<a-point x="100%" y="100%" content="Lorem ipsum dolor sit amet"></a-point>
<a-point x="0%" y="0%"><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
<a-point x="50%" y="50%"><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
<a-point x="100%" y="100%"><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
</annotate>
<br>
<p><strong>Annotate point attributes</strong></p>

<annotate src="./images/annotateSampleImage.png" width="350" alt="sampleImage">
<a-point x="25%" y="25%" content="Lorem ipsum dolor sit amet"></a-point>
<a-point x="50%" y="25%" content="Lorem ipsum dolor sit amet" size="60"></a-point>
<a-point x="75%" y="25%" content="Lorem ipsum dolor sit amet" header="Lorem ipsum"></a-point>
<a-point x="33%" y="50%" content="Lorem ipsum dolor sit amet" color="red"></a-point>
<a-point x="66%" y="50%" content="Lorem ipsum dolor sit amet" opacity="0.7"></a-point>
<a-point x="25%" y="75%" content="Lorem ipsum dolor sit amet" label="1"></a-point>
<a-point x="50%" y="75%" content="Lorem ipsum dolor sit amet" textColor="white" color="black" label="2" opacity="1"></a-point>
<a-point x="75%" y="75%" content="Lorem ipsum dolor sit amet" fontSize="30" label="3"></a-point>
<a-point x="25%" y="25%"><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
<a-point x="50%" y="25%" size="60"><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
<a-point x="75%" y="25%"><template #header>
<p>Lorem ipsum</p>
</template><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
<a-point x="33%" y="50%" color="red"><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
<a-point x="66%" y="50%" opacity="0.7"><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
<a-point x="25%" y="75%"><template #label>
<p>1</p>
</template><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
<a-point x="50%" y="75%" textColor="white" color="black" opacity="1"><template #label>
<p>2</p>
</template><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
<a-point x="75%" y="75%" fontSize="30"><template #label>
<p>3</p>
</template><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
</annotate>

<annotate src="./images/annotateSampleImage.png" width="600" alt="sampleImage">
<a-point x="33%" y="33%" content="Lorem ipsum dolor sit amet"></a-point>
<a-point x="66%" y="33%" content="Lorem ipsum dolor sit amet" trigger="hover focus"></a-point>
<a-point x="25%" y="66%" content="Lorem ipsum dolor sit amet" placement="left"></a-point>
<a-point x="50%" y="66%" content="Lorem ipsum dolor sit amet" placement="bottom"></a-point>
<a-point x="75%" y="66%" content="Lorem ipsum dolor sit amet" placement="right"></a-point>
<a-point x="33%" y="33%"><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
<a-point x="66%" y="33%" trigger="hover focus"><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
<a-point x="25%" y="66%" placement="left"><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
<a-point x="50%" y="66%" placement="bottom"><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
<a-point x="75%" y="66%" placement="right"><template #content>
<p>Lorem ipsum dolor sit amet</p>
</template></a-point>
</annotate>

<annotate src="./images/annotateSampleImage.png" width="1500" alt="sampleImage">
<a-point x="25%" y="50%" content="some test text" label="1"></a-point>
<a-point x="50%" y="50%" content="some test text" label="2" legend="bottom" header="some test text"></a-point>
<a-point x="75%" y="50%" content="some test text" label="3" legend="both" header="some test text"></a-point>
<a-point x="25%" y="50%"><template #label>
<p>1</p>
</template><template #content>
<p>some test text</p>
</template></a-point>
<a-point x="50%" y="50%" legend="bottom"><template #label>
<p>2</p>
</template><template #header>
<p>some test text</p>
</template><template #content>
<p>some test text</p>
</template></a-point>
<a-point x="75%" y="50%" legend="both"><template #label>
<p>3</p>
</template><template #header>
<p>some test text</p>
</template><template #content>
<p>some test text</p>
</template></a-point>
</annotate>

<annotate src="./images/annotateSampleImage.png" width="1500" alt="sampleImage">
<a-point x="25%" y="25%" content="some test text" label="1" legend="both"></a-point>
<a-point x="50%" y="25%" content="some test text" label="2" legend="both"></a-point>
<a-point x="75%" y="25%" content="some test text" label="3" legend="both"></a-point>
<a-point x="25%" y="50%" content="some test text" label="4" legend="both" header="some test text"></a-point>
<a-point x="50%" y="50%" content="some test text" label="5" legend="both" header="some test text"></a-point>
<a-point x="75%" y="50%" content="some test text" label="6" legend="both" header="some test text"></a-point>
<a-point x="25%" y="25%" legend="both"><template #label>
<p>1</p>
</template><template #content>
<p>some test text</p>
</template></a-point>
<a-point x="50%" y="25%" legend="both"><template #label>
<p>2</p>
</template><template #content>
<p>some test text</p>
</template></a-point>
<a-point x="75%" y="25%" legend="both"><template #label>
<p>3</p>
</template><template #content>
<p>some test text</p>
</template></a-point>
<a-point x="25%" y="50%" legend="both"><template #label>
<p>4</p>
</template><template #header>
<p>some test text</p>
</template><template #content>
<p>some test text</p>
</template></a-point>
<a-point x="50%" y="50%" legend="both"><template #label>
<p>5</p>
</template><template #header>
<p>some test text</p>
</template><template #content>
<p>some test text</p>
</template></a-point>
<a-point x="75%" y="50%" legend="both"><template #label>
<p>6</p>
</template><template #header>
<p>some test text</p>
</template><template #content>
<p>some test text</p>
</template></a-point>
</annotate>

<annotate src="./images/annotateSampleImage.png" width="1500" alt="sampleImage">
<a-point x="25%" y="25%"><template #content>
<h1 id="content">Content<a class="fa fa-anchor" href="#content" onclick="event.stopPropagation()"></a></h1>
</template></a-point>
<a-point x="50%" y="25%"><template #header>
<p>😊</p>
</template></a-point>
<a-point x="75%" y="25%"><template #label>
<p>❤️</p>
</template></a-point>
</annotate>
<p><strong>Annotate Point customised shapes</strong></p>
<annotate src="./images/annotateSampleImage.png" width="1500" alt="sampleImage">
Expand Down

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions packages/cli/test/functional/test_site/testAnnotate.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@
<a-point x="75%" y="50%" content="some test text" label="6" legend="both" header="some test text"/>
</annotate>

<!-- Markdown in content, header and label -->
<annotate src="./images/annotateSampleImage.png" width="1500" alt="sampleImage">
<a-point x="25%" y="25%" content="# Content" />
<a-point x="50%" y="25%" header=":blush:" />
<a-point x="75%" y="25%" label=":heart:"/>
</annotate>

**Annotate Point customised shapes**
<annotate src="./images/annotateSampleImage.png" width="1500" alt="sampleImage">
<a-point x="25%" y="25%">
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/html/MdAttributeRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,10 @@ export class MdAttributeRenderer {
processScrollTopButtonAttributes(node: MbNode) {
this.processAttributeWithoutOverride(node, 'icon', true);
}

processAnnotationPointAttributes(node: MbNode) {
this.processAttributeWithoutOverride(node, 'content', false);
this.processAttributeWithoutOverride(node, 'header', false);
this.processAttributeWithoutOverride(node, 'label', false);
}
}
3 changes: 3 additions & 0 deletions packages/core/src/html/NodeProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ export class NodeProcessor {
case 'scroll-top-button':
this.mdAttributeRenderer.processScrollTopButtonAttributes(node);
break;
case 'a-point':
this.mdAttributeRenderer.processAnnotationPointAttributes(node);
break;
case 'code':
setCodeLineNumbers(node, this.config.codeLineNumbers);
// fall through
Expand Down
80 changes: 80 additions & 0 deletions packages/vue-components/src/__tests__/Annotation.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { mount } from '@vue/test-utils';
import { Dropdown } from 'floating-vue';
import Annotation from '../annotations/Annotate.vue';
import AnnotationPoint from '../annotations/AnnotatePoint.vue';

const DEFAULT_STUBS = {
'a-point': AnnotationPoint,
'v-popover': Dropdown,
};

const ANNOTATION_POINTS = `
<a-point x="25%" y="25%" content="25% from the left and 25% from the top" />
<a-point x="50%" y="25%" content="50% from the left and 25% from the top" size="60"/>
<a-point x="75%" y="25%" content="75% from the left and 25% from the top" header="This has a header"/>
<a-point x="33%" y="50%" content="33% from the left and 50% from the top" color="red"/>
<a-point x="66%" y="50%" content="66% from the left and 50% from the top" opacity="0.7"/>
<a-point x="25%" y="75%" content="25% from the left and 75% from the top" label="1"/>
<a-point x="50%" y="75%" content="50% from the left and 75% from the top"
textColor="white" color="black" label="2" opacity="1"/>
<a-point x="75%" y="75%" content="75% from the left and 75% from the top" fontSize="30" label="3"/>
`;

const CUSTOMISED_ANNOTATION_POINTS = `
<a-point x="25%" y="25%" content="25% from the left and 25% from the top">
<div style="color:red">Hi</div>
</a-point>
<a-point x="75%" y="75%" content="75% from the left and 75% from the top">
<span class="badge bg-primary">Primary</span>
</a-point>
`;

const MARKDOWN_ANNOTATION_POINTS = `
<a-point x="25%" y="25%" content="[link](https://markbind.org/userGuide/gettingStarted.html)" />
<a-point x="50%" y="50%" header="### Header" />
<a-point x="75%" y="75%" label=":rocket:" />
`;

describe('Annotation', () => {
test('with different visual annotation points', async () => {
const wrapper = mount(Annotation, {
propsData: {
src: './annotateSampleImage.png',
},
slots: {
default: ANNOTATION_POINTS,
},
stubs: DEFAULT_STUBS,
});
await wrapper.vm.$nextTick();
expect(wrapper.element).toMatchSnapshot();
});

test('with customised annotation points', async () => {
const wrapper = mount(Annotation, {
propsData: {
src: './annotateSampleImage.png',
},
slots: {
default: CUSTOMISED_ANNOTATION_POINTS,
},
stubs: DEFAULT_STUBS,
});
await wrapper.vm.$nextTick();
expect(wrapper.element).toMatchSnapshot();
});

test('with markdown in header, content and label', async () => {
const wrapper = mount(Annotation, {
propsData: {
src: './annotateSampleImage.png',
},
slots: {
default: MARKDOWN_ANNOTATION_POINTS,
},
stubs: DEFAULT_STUBS,
});
await wrapper.vm.$nextTick();
expect(wrapper.element).toMatchSnapshot();
});
});
Loading

0 comments on commit 58fbbd0

Please sign in to comment.