Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Line Annotations #115

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Add Line Annotations #115

wants to merge 3 commits into from

Conversation

karlhorky
Copy link

@karlhorky karlhorky commented May 15, 2021

Followup to #51 with the new version of Code Surfer

@pomber what are your thoughts on this?

Simple example:

<CodeSurfer
  steps={[
    {
      code: `This line will have an "abc" annotation here ->
This line will have an "def" annotation here ->`,
      lang: 'jsx',
      annotations: {
        1: <span>abc</span>,
        2: <span>def</span>,
      },
    },
  ]}
  progress={0}
/>

More complex example:

<CodeSurfer
  lang="jsx"
  steps={[
    {
      code: require('!raw-loader!./packages/example-1-simple-cra/src/index.js'),
      lang: 'jsx',
      annotations: {
        1: (
          <Brace side="left" height="5em">
            JavaScript
          </Brace>
        ),
        8: (
          <Brace side="right" height="3em" style={{}}>
            JSX
          </Brace>
        ),
        13: (
          <Brace side="left" height="3em">
            JavaScript
          </Brace>
        ),
        22: (
          <Brace side="right" height="6em" style={{ marginTop: '-2.5em' }}>
            JSX
          </Brace>
        ),
        27: (
          <>
            <Brace side="top" width="5.7em" style={{ marginLeft: '-1.3em' }}>
              JavaScript
            </Brace>
            <Brace side="top" width="2.2em" style={{ marginLeft: '5.2em' }}>
              JSX
            </Brace>
            <Brace side="top" width="13.3em" style={{ marginLeft: '8.2em' }}>
              JavaScript
            </Brace>
          </>
        ),
      },
    },
  ]}
  progress={0}
/>

Screen Shot 2021-05-15 at 19 06 28

@karlhorky karlhorky mentioned this pull request May 15, 2021
1 task
@karlhorky
Copy link
Author

karlhorky commented May 15, 2021

For anyone who doesn't want to wait for this to be accepted / merged, you can apply via patch-package, with the following files in your project:

@code-surfer+standalone+3.1.1.patch

diff --git a/node_modules/@code-surfer/standalone/dist/standalone.esm.js b/node_modules/@code-surfer/standalone/dist/standalone.esm.js
index 37c0d32..c40f13a 100644
--- a/node_modules/@code-surfer/standalone/dist/standalone.esm.js
+++ b/node_modules/@code-surfer/standalone/dist/standalone.esm.js
@@ -663,7 +663,7 @@ function LineList(_ref) {
         style: getTokenStyle(t, tokeni),
         key: tokeni
       }, token);
-    })));
+    }), stepPair.prev.annotations && stepPair.prev.annotations[lineKey + 1]));
   }));
 }
 

@code-surfer+step-parser+3.1.1.patch

diff --git a/node_modules/@code-surfer/step-parser/dist/step-parser.esm.js b/node_modules/@code-surfer/step-parser/dist/step-parser.esm.js
index 9992da5..71dbe51 100644
--- a/node_modules/@code-surfer/step-parser/dist/step-parser.esm.js
+++ b/node_modules/@code-surfer/step-parser/dist/step-parser.esm.js
@@ -527,7 +527,8 @@ function parseSteps(inputSteps) {
       focusCount: focusCount,
       longestLineIndex: getLongestLineIndex(code),
       title: inputSteps[i].title,
-      subtitle: inputSteps[i].subtitle
+      subtitle: inputSteps[i].subtitle,
+      annotations: inputSteps[i].annotations
     });
   }); // split tokens into columns when needed
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant