Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
206 changes: 206 additions & 0 deletions lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# Figure Element

> Generate an HTML string for displaying an SVG figure as an image in a GitHub Markdown file.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var createElement = require( '@stdlib/_tools/markdown/img-svg-figure' );
```

#### createElement( \[options] )

Generates an HTML `string` for displaying an SVG figure as an image in a GitHub Markdown file.

```javascript
var html = createElement();
// returns '<div class="figure" align="center" data-figure="">\n <img src="" alt="">\n <br>\n</div>'
```

The function accepts the following `options`:

- **className**: element class name. Default: `'figure'`.
- **align**: element alignment. Default: `'center'`.
- **label**: figure label.
- **src**: image source URL.
- **alt**: alternative image text.

Each `option` corresponds an HTML attribute. For example, to set the image source URL, set the `src` option.

```javascript
var opts = {
'src': 'https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@master/docs/img/fig1.svg'
};

var html = createElement( opts );
// returns '<div class="figure" align="center" data-figure="">\n <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@master/docs/img/fig1.svg" alt="">\n <br>\n</div>'
```

To include a figure label in the element, set the `label` option.

```javascript
var opts = {
'label': 'fig:fig1',
'src': 'https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@master/docs/img/fig1.svg'
};

var html = createElement( opts );
// returns '<div class="figure" align="center" data-figure="fig:fig1">\n <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@master/docs/img/fig1.svg" alt="">\n <br>\n</div>'
```

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var createElement = require( '@stdlib/_tools/markdown/img-svg-figure' );

var opts = {
'className': 'fig',
'align': 'center',
'label': 'fig:padding',
'src': 'https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@master/lib/node_modules/@stdlib/plot/vega/padding/ctor/docs/img/figure_padding.svg',
'alt': 'A visualization showing padding margins.'
};

var html = createElement( opts );

console.log( html );
// => '<div class="fig" align="center" data-figure="fig:padding">\n <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@master/lib/node_modules/@stdlib/plot/vega/padding/ctor/docs/img/figure_padding.svg" alt="A visualization showing padding margins.">\n <br>\n</div>'
```

</section>

<!-- /.examples -->

* * *

<section class="cli">

## CLI

<!-- CLI usage documentation. -->

<section class="usage">

### Usage

```text
Usage: ghimgfig [options]

Options:

-h, --help Print this message.
-V, --version Print the package version.
--class name Element class name. Default: figure.
--align alignment Element alignment. Default: center.
--label label Figure label.
--src url Image source URL.
--alt text Alternative image text.
```

</section>

<!-- /.usage -->

<!-- CLI usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- CLI usage examples. -->

<section class="examples">

### Examples

```bash
$ ghimgfig --label 'fig:fig1' --src 'https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@master/docs/img/fig1.svg'
<div class="figure" align="center" data-figure="fig:fig1">
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@master/docs/img/fig1.svg" alt="">
<br>
</div>
```

</section>

<!-- /.examples -->

</section>

<!-- /.cli -->

<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

</section>

<!-- /.links -->
78 changes: 78 additions & 0 deletions lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/bin/cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env node

/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var join = require( 'path' ).join;
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
var CLI = require( '@stdlib/cli/ctor' );
var createElement = require( './../lib' );


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var flags;
var opts;
var cli;

// Create a command-line interface:
cli = new CLI({
'pkg': require( './../package.json' ),
'options': require( './../etc/cli_opts.json' ),
'help': readFileSync( join( __dirname, '..', 'docs', 'usage.txt' ), {
'encoding': 'utf8'
})
});

// Get any provided command-line options:
flags = cli.flags();
if ( flags.help || flags.version ) {
return;
}

// Extract options...
opts = {};
if ( flags[ 'class' ] ) {
opts.className = flags[ 'class' ];
}
if ( flags.align ) {
opts.align = flags.align;
}
if ( flags.label ) {
opts.label = flags.label;
}
if ( flags.src ) {
opts.src = flags.src;
}
if ( flags.alt ) {
opts.alt = flags.alt;
}
console.log( createElement( opts ) ); // eslint-disable-line no-console
}

main();
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

Usage: ghimgfig [options]

Options:

-h, --help Print this message.
-V, --version Print the package version.
--class name Element class name. Default: figure.
--align alignment Element alignment. Default: center.
--label label Figure label.
--src url Image source URL.
--alt text Alternative image text.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"string": [
"class",
"align",
"label",
"src",
"alt"
],
"boolean": [
"help",
"version"
],
"alias": {
"help": [
"h"
],
"version": [
"V"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

var createElement = require( './../lib' );

var opts = {
'className': 'fig',
'align': 'center',
'label': 'fig:padding',
'src': 'https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@master/lib/node_modules/@stdlib/plot/vega/padding/ctor/docs/img/figure_padding.svg',
'alt': 'A visualization showing padding margins.'
};

var html = createElement( opts );

console.log( html );
// => '<div class="fig" align="center" data-figure="fig:padding">\n <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@master/lib/node_modules/@stdlib/plot/vega/padding/ctor/docs/img/figure_padding.svg" alt="A visualization showing padding margins.">\n <br>\n</div>'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"className": "figure",
"align": "center",
"label": "",
"src": "",
"alt": ""
}
Loading
Loading