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

Create OSCALMarkdownProse Component #536

Merged
merged 10 commits into from
Aug 4, 2022
Merged

Conversation

kperk103
Copy link
Contributor

@kperk103 kperk103 commented Aug 4, 2022

This will add a basic implementation of an OSCALMarkdownProse
component. Once the component has been implemented as desired, it will
be used to handle markdown in prose statements, metadata titles,
system implementation remarks, and control implementation descriptions.

Currently it is a draft and any suggestions are greatly appreciated.

Part of #156.

This will add a basic implementation of a possible OSCALMarkdownProse
component.
@tuckerzp
Copy link
Contributor

tuckerzp commented Aug 4, 2022

In order to get markdown to display at a basic level throughout the application, this seems like a decent start. @kylelaker & @brian-easyd I know there was some discussion outside the issue on what we want here. Is there anything that you'd think we would want to add for an initial implementation of dealing with markdown?

@kylelaker
Copy link
Contributor

Great start! I think initially we want a test just to make sure that this does what we expect; so:

<OSCALMarkdownProse>*Hello*, **world**</OSCALMarkdownProse>

Should look like:

Hello, world

And that

const text = "<script>alert('Nasty script!')</script>"
<OSCALMarkdownProse children={text}/>

Doesn't do anything gross. In fact, I almost wonder if we should just pass skipHtml to the component?

This is first test to see if there markdown can be converted
by matching it with its corresponding HTML

Currently this test is failing due to a JEST configuration error
between JS and TS. What would be the best way to resolve this?
I've looked online and it changes the JEST configurations however
I don't want to make any unecessary changes to the dependencies
@schen2166
Copy link
Contributor

This is a screenshot of the error I am getting with the React testing, as mentioned in the previous commit

@kperk103
Copy link
Contributor Author

kperk103 commented Aug 4, 2022

This is a screenshot of the error I am getting with the React testing, as mentioned in the previous commit

We found this and tried the suggestions that were mentioned but couldn't get it working: https://stackoverflow.com/questions/49263429/jest-gives-an-error-syntaxerror-unexpected-token-export

@brian-comply0
Copy link
Contributor

I want to make sure everyone is aware of NIST's official description for exactly what should be handled by Markup-line and Markup-multiline:
https://pages.nist.gov/OSCAL/reference/datatypes/#markup-data-types

Ultimately our capabilities should do exactly this. No more. No less. For now I am OK with achieving a reasonable sub-set and expanding in a later sprint if this proves too big an effort for one sprint.

Also, as I mentioned yesterday, the stored data format must be markdown, but that does not automatically mean the editor must be markdown.

Ideally the user interface is friendly to security practitioners who are not likely to know markdown, yet can also accept markdown for those who know it.

Again, for now I'm good with one or the other (non-markdown friendly or markdown-friendly), provided any solution we select allows us to grow on top of the work we do now rather than having to replace it.

@kylelaker
Copy link
Contributor

I want to make sure everyone is aware of NIST's official description for exactly what should be handled by Markup-line and Markup-multiline: https://pages.nist.gov/OSCAL/reference/datatypes/#markup-data-types

Ultimately our capabilities should do exactly this. No more. No less. For now I am OK with achieving a reasonable sub-set and expanding in a later sprint if this proves too big an effort for one sprint.

Hmm so that looks like another case of markdown with extensions since tables are supported. But then the single-line version has a more limited set... That'll take more time to actually fine-tune. And we have to decide if we want different behavior for viewing vs editing. We probably also need to our best to display whatever is there, even if it's not technically totally valid (someone put a table in a markup-line) but we shouldn't let a user write something like that.

Also, as I mentioned yesterday, the stored data format must be markdown, but that does not automatically mean the editor must be markdown.

We should be able to accomplish this by only using this new Component when viewing/displaying the text and not try to perform any translation of Markdown to HTML (for now).

Ideally the user interface is friendly to security practitioners who are not likely to know markdown, yet can also accept markdown for those who know it.

I'd like to handle this in a separate ticket (can we create one)? This will require finding/adding/integrating a WYSIWYG editor of some sort or using something like the text field editor here on GitHub. That will be a much larger lift.

Again, for now I'm good with one or the other (non-markdown friendly or markdown-friendly), provided any solution we select allows us to grow on top of the work we do now rather than having to replace it.

Hopefully we get that by starting to add a custom component (as we're doing here) that's very minimal and then adding more features over time. This was why I advocated for this approach rather than just using the <ReactMarkdown> component "raw" all over the place.

This adds a brief description of the OSCALMarkdownProse component
and adds a configuration in package.json so that the component tests
will be able to run
@kylelaker kylelaker marked this pull request as ready for review August 4, 2022 16:13
@easy-dynamics-oscal-automation easy-dynamics-oscal-automation bot requested a review from a team August 4, 2022 16:13
@kylelaker kylelaker marked this pull request as draft August 4, 2022 16:14
Made tests to see if the component can convert string literals to
to its equivalent in HTML

So far there are tests for
 - plaintext
 - Bold, Italics, Plaintext mixed,
 - Hyperlinks
 - Images
@schen2166
Copy link
Contributor

Currently the tests check whether something in markdown will convert to its HTML equivalent.
I'm wondering what other tests I should include in the OSCALMarkdownProse tests?
A new test will expect text in markdown to equal its equivalent in HTML

@kylelaker
Copy link
Contributor

can we fix the linting?

@@ -0,0 +1,40 @@
import React from "react";
import { OSCALMarkdownProse } from "./OSCALMarkdownProse";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { OSCALMarkdownProse } from "./OSCALMarkdownProse";
import OSCALMarkdownProse from "./OSCALMarkdownProse";

Right now the component tests are failing and I believe if you remove the brackets around OSCALMarkdownProse it will prevent them from failing

import ReactDomServer from "react-dom/server";
import OSCALMarkdownProse from "./OSCALMarkdownProse";

export default function asHtml(input) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be exported? What happens if we don't do that?

Note: line does not allow multiple lines so not sure if this is
what multiline markdown should be.

I am unable to get embedded HTML tags like
<h1>
 body
  <h2> header 2 </h2>
     more text
</h1>

I've also tried markdown with mutiple lines sich as
`const multiline string = "line 1 \
line 2 \
line 3\"`

and converting that to HTML and caused linting errors
Comment on lines 58 to 61
const multilineMarkdown =
"this should b here # h1 Heading 8- ## h2 Heading This is in heading 2 ### h3 Heading This is in heading 3 #### h4 Heading ##### **h5 Heading** ###### h6 Heading ";
const multilineAsHTML =
"<p>this should b here # h1 Heading 8- ## h2 Heading This is in heading 2 ### h3 Heading This is in heading 3 #### h4 Heading ##### <strong>h5 Heading</strong> ###### h6 Heading</p>";
Copy link
Contributor

@kylelaker kylelaker Aug 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So uhh despite being called "multiline" this is just one line.

Suggested change
const multilineMarkdown =
"this should b here # h1 Heading 8- ## h2 Heading This is in heading 2 ### h3 Heading This is in heading 3 #### h4 Heading ##### **h5 Heading** ###### h6 Heading ";
const multilineAsHTML =
"<p>this should b here # h1 Heading 8- ## h2 Heading This is in heading 2 ### h3 Heading This is in heading 3 #### h4 Heading ##### <strong>h5 Heading</strong> ###### h6 Heading</p>";
const multilineMarkdown = `
this should be here
# h1 heading
## h2 Heading
This is in heading 2
### h3 Heading
This is in heading 3
##### **h5 Heading**
`;
const multilineHtml = "<p>this should be here</p><h1>h1 heading</h1><h2>h2 Heading</h2><p>This is in heading 2</p><h3>h3 Heading</h3><p>This is in heading 3 </p><h5><strong>h5 Heading</strong></h5>";

ya know +/- some formatting and spacing and all that

@kperk103 kperk103 marked this pull request as ready for review August 4, 2022 20:08
@schen2166 schen2166 linked an issue Aug 4, 2022 that may be closed by this pull request
Copy link
Contributor

@kylelaker kylelaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy with this as a base component with simple tests to start the integration work with.

@easy-dynamics-oscal-automation easy-dynamics-oscal-automation bot requested a review from a team August 4, 2022 20:48
Copy link
Contributor

@Bronstrom Bronstrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a solid start to handle markdown throughout the application consistently. I also like seeing were creating our tests at the beginning of this issue. Great work!

@kylelaker kylelaker merged commit ae17d39 into develop Aug 4, 2022
@kylelaker kylelaker deleted the feature/handle-markdown branch August 4, 2022 23:07
@naiqbal
Copy link

naiqbal commented Aug 12, 2022

@brian-comply0
Copy link
Contributor

I agree this is complete

@kylelaker kylelaker added the enhancement New feature or request label Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle Markdown in Prose and Other Fields
7 participants