jupyter-ijavascript-utils 1.58.0 → 1.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/DOCS.md CHANGED
@@ -74,6 +74,9 @@ Give it a try here:
74
74
  [![Binder:what can I do with this](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/paulroth3d/jupyter-ijavascript-utils/main?labpath=example.ipynb)
75
75
 
76
76
  ## What's New
77
+ * 1.59 -
78
+ * #95 - give control with page breaks. So we can render text before the page break (like for headers) - or even get the html used and render it how we want. (ex: {@link module:ijs.generatePageBreakStylesHTML|ijs.printPageBreak})
79
+ * #96 - Support {@link module:ijs.internalComment|ijs.internalComment} in notebooks (meaning it can render in markdown, but can be disabled when preparing to print)
77
80
  * 1.58 -
78
81
  * #91 - add {@link module:object.splitIntoDatums|splitIntoDatums(collection, fieldsToSplitBy)} - to make working with datum libraries - like vega-lite - easier
79
82
  * #92 - make using the cache easier for {@link module:file.useCache|file.useCache()} - as you can say to use the cache, and it will still work if the cache file does not exist yet.
package/Dockerfile CHANGED
@@ -1,3 +1,3 @@
1
1
  # syntax=docker/dockerfile:1
2
2
 
3
- FROM darkbluestudios/jupyter-ijavascript-utils:binder_1.58.0
3
+ FROM darkbluestudios/jupyter-ijavascript-utils:binder_1.59.0
package/README.md CHANGED
@@ -54,6 +54,9 @@ This is not intended to be the only way to accomplish many of these tasks, and a
54
54
  ![Screenshot of example notebook](docResources/img/mainExampleNotebook.png)
55
55
 
56
56
  # What's New
57
+ * 1.59 -
58
+ * #95 - give control with page breaks. So we can render text before the page break (like for headers) - or even get the html used and render it how we want.
59
+ * #96 - Support internal comments in notebooks (meaning it can render in markdown, but can be disabled when preparing to print)
57
60
  * 1.58 -
58
61
  * #91 - add object.splitIntoDatums - to make working with datum libraries - like vega-lite - easier
59
62
  * #92 - make using the cache easier - as you can say to use the cache, and it will still work if the cache file does not exist yet.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jupyter-ijavascript-utils",
3
- "version": "1.58.0",
3
+ "version": "1.59.0",
4
4
  "description": "Utilities for working with iJavaScript - a Jupyter Kernel",
5
5
  "homepage": "https://jupyter-ijavascript-utils.onrender.com/",
6
6
  "license": "MIT",
package/src/ijs.js CHANGED
@@ -29,6 +29,11 @@ require('./_types/global');
29
29
  * * {@link module:ijs.clearOutput|ijs.clearOutput} - clears the output to declutter results (like importing libraries, or functions)
30
30
  * * {@link module:ijs.initializePageBreaks|ijs.initializePageBreaks} - call at least once to allow pageBreaks when rendering PDFs
31
31
  * * {@link module:ijs.printPageBreak|ijs.printPageBreak} - call to print a page break when rendering PDFs
32
+ * * {@link module:ijs.generatePageBreakStylesHTML|ijs.generatePageBreakStylesHTML} - generates the html used in to allow for pagebreaks
33
+ * (so you can render them as you'd like)
34
+ * * {@link module:ijs.generatePageBreakHTML|ijs.generatePageBreakHTML} - generates the html that uses the styles to render pagebreaks
35
+ * (so you can render them as you'd like)
36
+ * * {@link module:ijs.internalComment|ijs.internalComment} - render markdown, but be able to turn it off, prior to printing
32
37
  * * using a cache for long running executions
33
38
  * * {@link module:ijs.useCache|ijs.useCache()} - perform an expensive calculation and write to a cache, or read from the cache transparently
34
39
  *
@@ -235,6 +240,8 @@ module.exports.detectIJS = function detectIJS() {
235
240
  * ![Screenshot of markdown](img/ijsMarkdown.png)
236
241
  *
237
242
  * @param {String} markdownText - The markdown to be rendered
243
+ * @param {*} markdownText - the markdown text to render
244
+ * @param {Jupyter$$} [display] - the display to render the output to.
238
245
  * @example
239
246
  *
240
247
  * utils.ijs.markdown(`# Overview
@@ -246,6 +253,33 @@ module.exports.markdown = function markdown(markdownText, display) {
246
253
  displayToUse.mime({ 'text/markdown': markdownText });
247
254
  };
248
255
 
256
+ /**
257
+ * Capture internal comments that can render as markdown (including images)
258
+ * but be turned off - so they are not rendered in the final output
259
+ *
260
+ * ```
261
+ * utils.ijs.internalComment(true, `![Screenshot](localhost://path-to-file)`);
262
+ * ```
263
+ *
264
+ * and then when preparing to ship, you don't include it
265
+ *
266
+ * ```
267
+ * printable=true
268
+ * utils.ijs.internalComment(!printable, `![Screenshot](localhost://path-to-file)`);
269
+ * ```
270
+ *
271
+ * @param {Boolean} shouldRender - whether the comment should be rendered to the output
272
+ * @param {String} markdownText - the markdown text to render
273
+ * @param {Jupyter$$} [display] - the display to render the output to.
274
+ */
275
+ module.exports.internalComment = function internalComment(shouldRender, markdownText, display) {
276
+ if (!shouldRender) {
277
+ IJSUtils.clearOutput();
278
+ } else {
279
+ IJSUtils.markdown(markdownText, display);
280
+ }
281
+ };
282
+
249
283
  /**
250
284
  * List the globals currently defined.
251
285
  *
@@ -604,6 +638,36 @@ module.exports.clearOutput = function clearOutput(outputText = '') {
604
638
  };
605
639
  module.exports.noOutputNeeded = module.exports.clearOutput;
606
640
 
641
+ /**
642
+ * Returns the HTML used for generating pageBreaks within the library.
643
+ *
644
+ * This gives you control over rendering the text together
645
+ *
646
+ * ```
647
+ * utils.ijs.generatePageBreakStylesHTML();
648
+ * // <style>
649
+ *
650
+ * //-- an identifier that can be used to find if this script exists on the page
651
+ * \/\* ID:___InitializePageBreaks___ \*\/
652
+ *
653
+ * // @media print {
654
+ * // .pagebreak { page-break-before: always; }
655
+ * // }
656
+ *
657
+ * // </style>
658
+ * ```
659
+ *
660
+ * @returns {String} - the html styles tag used to allow for page breaks to be generated
661
+ */
662
+ module.exports.generatePageBreakStylesHTML = function generatePageBreakStylesHTML() {
663
+ return `<style>
664
+ /* ID:___InitializePageBreaks___ */
665
+ @media print {
666
+ .pagebreak { page-break-before: always; } /* page-break-after works, as well */
667
+ }
668
+ </style>`;
669
+ };
670
+
607
671
  /**
608
672
  * Required to be called first - in order to write page-breaks in the html results.
609
673
  *
@@ -634,8 +698,26 @@ module.exports.noOutputNeeded = module.exports.clearOutput;
634
698
  *
635
699
  * * end of document
636
700
  * ```
701
+ *
702
+ * Note, sometimes you want to include a text prior to the page break,
703
+ * like mentioning that a page is left intentionally blank - or to identify
704
+ * this is the cell that has the style - so it shouldn't be removed prior to printing.
705
+ *
706
+ * ```
707
+ * utils.ijs.initializePageBreaks('<h1>This page left intentionally blank</h1>');
708
+ * ```
709
+ *
710
+ * Or, perhaps you always want a page break after defining the styles
711
+ *
712
+ * ```
713
+ * utils.ijs.initializePageBreaks(null, utils.ijs.generatePageBreakHTML());
714
+ * ```
715
+ *
716
+ * @param {String} [htmlToInjectBefore] - optional html text to include prior to the pageBreak
717
+ * (This can be helpful like - page left intentionally blank)
718
+ * @param {String} [htmlToInjectAfter] - optional html text to include prior to the pageBreak
637
719
  */
638
- module.exports.initializePageBreaks = function initializePageBreaks() {
720
+ module.exports.initializePageBreaks = function initializePageBreaks(htmlToInjectBefore, htmlToInjectAfter) {
639
721
  //-- you must be in iJavaScript container to rendeer
640
722
  const context = IJSUtils.detectContext();
641
723
 
@@ -643,20 +725,50 @@ module.exports.initializePageBreaks = function initializePageBreaks() {
643
725
  return;
644
726
  }
645
727
 
646
- context.$$.html(`<style>
647
- @media print {
648
- .pagebreak { page-break-before: always; } /* page-break-after works, as well */
649
- }
650
- </style>
651
- <div class="pagebreak"></div>
652
- `);
728
+ const cleanInjectionPrior = htmlToInjectBefore || '';
729
+ const htmlToRender = IJSUtils.generatePageBreakStylesHTML();
730
+ const cleanInjectionAfter = htmlToInjectAfter || '';
731
+
732
+ context.$$.html(`
733
+ ${cleanInjectionPrior}
734
+ ${htmlToRender}
735
+ ${cleanInjectionAfter}`);
736
+ };
737
+
738
+ /**
739
+ * Generates the html used for creating a page break used by the library.
740
+ *
741
+ * This gives you options about when and how to render it.
742
+ *
743
+ * ```
744
+ * utils.ijs.generatePageBreakHTML();
745
+ * //-- uses the style defined in initializePageBreaks
746
+ * // <div class="pagebreak"></div>
747
+ * ```
748
+ *
749
+ * For example, you can use this so you automatically have a page break after generating the styles
750
+ *
751
+ * ```
752
+ * utils.ijs.initializePageBreaks(null, utils.ijs.generatePageBreakHTML());
753
+ * ```
754
+ *
755
+ * @returns {String}
756
+ * @see {@link module:ijs.printPageBreak|ijs.printPageBreak}
757
+ * @see {@link module:ijs.initializePageBreaks|ijs.initializePageBreaks}
758
+ */
759
+ module.exports.generatePageBreakHTML = function generatePageBreakHTML() {
760
+ return '<div class="pagebreak"></div>';
653
761
  };
654
762
 
655
763
  /**
656
764
  * After the {@see module:ijs.initializePageBreaks|utils.ijs.initializePageBreaks} is called,
657
765
  * this will create another page break.
766
+ *
767
+ * @param {String} [htmlToInjectBefore] - optional html text to include prior to the pageBreak
768
+ * (This can be helpful like - page left intentionally blank)
769
+ * @param {String} [htmlToInjectAfter] - optional html text to include prior to the pageBreak
658
770
  */
659
- module.exports.printPageBreak = function printPageBreak() {
771
+ module.exports.printPageBreak = function printPageBreak(htmlToInjectBefore, htmlToInjectAfter) {
660
772
  //-- you must be in iJavaScript container to rendeer
661
773
  const context = IJSUtils.detectContext();
662
774
 
@@ -664,7 +776,9 @@ module.exports.printPageBreak = function printPageBreak() {
664
776
  return;
665
777
  }
666
778
 
667
- context.$$.html('<div class="pagebreak"></div>');
779
+ const htmlToRender = IJSUtils.generatePageBreakHTML();
780
+
781
+ context.$$.html(`${htmlToInjectBefore || ''}${htmlToRender}${htmlToInjectAfter || ''}`);
668
782
  };
669
783
 
670
784
  /**