{"id":15398284,"url":"https://github.com/ldionne/reveal-sampler","last_synced_at":"2025-04-15T22:30:53.467Z","repository":{"id":147050133,"uuid":"55261197","full_name":"ldionne/reveal-sampler","owner":"ldionne","description":"A reveal.js plugin to fetch code samples from source files","archived":false,"fork":false,"pushed_at":"2020-06-20T17:08:07.000Z","size":1510,"stargazers_count":26,"open_issues_count":6,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-29T03:41:30.417Z","etag":null,"topics":["reveal-js","reveal-plugin","sampler","slide"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ldionne.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-01T20:44:42.000Z","updated_at":"2024-08-27T06:02:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"5d0ee184-e45a-4176-86dd-32b2e0a66833","html_url":"https://github.com/ldionne/reveal-sampler","commit_stats":{"total_commits":35,"total_committers":2,"mean_commits":17.5,"dds":0.2571428571428571,"last_synced_commit":"cd4a07d8adbb998397fbe1985a7313c32716ddb4"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ldionne%2Freveal-sampler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ldionne%2Freveal-sampler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ldionne%2Freveal-sampler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ldionne%2Freveal-sampler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ldionne","download_url":"https://codeload.github.com/ldionne/reveal-sampler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249165884,"owners_count":21223343,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["reveal-js","reveal-plugin","sampler","slide"],"created_at":"2024-10-01T15:42:11.584Z","updated_at":"2025-04-15T22:30:52.021Z","avatar_url":"https://github.com/ldionne.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## sampler.js\n\u003e A [reveal.js][] plugin to include code samples in slides\n\n\n### Usage\nFirst, initialize the plugin in the `dependencies` part of the reveal.js config:\n\n```js\n{ src: 'plugin/sampler.js' }\n```\n\nThis assumes that you copied the `sampler.js` file to `plugin/sampler.js` in\nyour reveal.js tree, but you can obviously pick whatever path you want. To\ninclude a code sample in a slide, use `\u003ccode\u003e` tags as follows:\n\n```html\n\u003cpre\u003e\u003ccode data-sample='path/to/source#sample-name'\u003e\u003c/code\u003e\u003c/pre\u003e\n```\n\nThe plugin will extract the sample named `sample-name` from the source file\nwhose path is given, and write it inside the `\u003ccode\u003e` tag. If no `sample-name`\nis given, the whole file is included. It is also possible to use line numbers\ninstead of a sample name to delimit a code snippet. The basic syntax is\n`path/to/file#start-end`, but multiple ranges or individual line numbers\nare supported too:\n\n```html\n\u003cpre\u003e\u003ccode data-sample='path/to/source#5-9'\u003e\u003c/code\u003e\u003c/pre\u003e\n\u003cpre\u003e\u003ccode data-sample='path/to/source#5-9,14-18'\u003e\u003c/code\u003e\u003c/pre\u003e\n\u003cpre\u003e\u003ccode data-sample='path/to/source#5,7,9'\u003e\u003c/code\u003e\u003c/pre\u003e\n\u003cpre\u003e\u003ccode data-sample='path/to/source#5-9,14,15'\u003e\u003c/code\u003e\u003c/pre\u003e\n```\n\nThe plugin will also add the `language-xxx` class to the `\u003ccode\u003e` tag, where\n`xxx` is the extension of the source file, so that code highlighting triggers\nproperly if set up. This usually works out of the box, because [highlight.js][]\ncan recognize the extensions associated to most languages. If you need to\nexplicitly set the language to use (e.g. because the file extension is\nmisleading), set the `language-xxx` class yourself on the `\u003ccode\u003e` tag and\nthe plugin will leave it alone.\n\n### Annotating source files\n\nTo define a named sample inside a source file, use the following syntax:\n\n```\nsample(sample-name)\ncode-inside-the-sample\nend-sample\n```\n\n`sampler.js` will parse the source file, and anything between the `sample(sample-name)`\nand the `end-sample` tags will be taken to be a code sample named `sample-name`.\nNote that anything on the same line as one of the special tags will not be taken\nas part of the sample, which is what allows this plugin to be language-agnostic,\nby commenting the tags in your source code. For example:\n\n```c++\n// sample(main)\nint main() {\n    std::cout \u003c\u003c \"this is C++ code\" \u003c\u003c std::endl;\n}\n// end-sample\n```\n\nMultiple samples can appear in the same source file, as long as they have\ndifferent names. If many samples have the same name, they will be considered\nas a single sample and concatenated together. For example, the following code\nwill create a single sample with name 'foo':\n\n```c++\n// sample(foo)\nfirst part of the sample\n// end-sample\n\nsome code not in the sample\n\n// sample(foo)\nsecond part of the sample\n// end-sample\n```\n\nWithin a sample, any line containing `skip-sample` will be skipped, which\nallows leaving implementation details out of slides:\n\n```c++\n// sample(foo)\nclass Foo {\n    void implementation_detail(); // skip-sample\n    void hello() { std::cout \u003c\u003c \"hello!\" \u003c\u003c std::endl; }\n};\n// end-sample\n```\n\n### Marking lines in a sample\nSpecific lines or line ranges can be marked in a sample. To do this, use the\n`data-sample-mark` attribute as follows:\n\n```html\n\u003cpre\u003e\u003ccode data-sample='path/to/source#sample-name' data-sample-mark=\"1,3\"\u003e\u003c/code\u003e\u003c/pre\u003e\n```\n\nThe line numbers specified in `data-sample-mark` are relative to the snippet\nitself, not to the file from which the snippet was extracted. Also, line\nranges are supported, just like for extracting snippets from a file.\n\n### Remove indentation\nIf all lines of the sample have an overall indentation you can remove it using the \nattribute `data-sample-indent`.\n\n```html\n\u003cpre\u003e\u003ccode data-sample='path/to/source#sample-name' data-sample-indent=\"remove\"\u003e\u003c/code\u003e\u003c/pre\u003e\n\u003cpre\u003e\u003ccode data-sample='path/to/source#sample-name' data-sample-indent=\"keep\"\u003e\u003c/code\u003e\u003c/pre\u003e\n```\n\nYou can change the default behaviour (snippets without the attribute) using\nthe option `sampler.removeIndentation`. The default value is `false`.\n\n```js\n{ \n    sampler : {\n        removeIndentation: true\n    } \n}\n```\n\n\n\n\n### Example\n\nIt's that simple! To get started, you can find an example of using the plugin\nin the `example/` directory.\n\n\n\u003c!-- Links --\u003e\n[highlight.js]: https://highlightjs.org\n[reveal.js]: https://github.com/hakimel/reveal.js/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fldionne%2Freveal-sampler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fldionne%2Freveal-sampler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fldionne%2Freveal-sampler/lists"}