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

Remove markdown from publikator #963

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
124 changes: 37 additions & 87 deletions apps/publikator/components/Tree/Diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,7 @@ import {
IconButton,
} from '@project-r/styleguide'

export const TREE_DIFF_QUERY = gql`
query TreeDiff($repoId: ID!, $commitId: ID!, $parentCommitId: ID!) {
repo(id: $repoId) {
id

commit: commit(id: $commitId) {
id
markdown
}

parentCommit: commit(id: $parentCommitId) {
id
markdown
}
}
}
`

export const SLATE_DIFF_QUERY = gql`
const DIFF_QUERY = gql`
query TreeDiff($repoId: ID!, $commitId: ID!, $parentCommitId: ID!) {
repo(id: $repoId) {
id
Expand Down Expand Up @@ -97,77 +79,45 @@ export default function TreeDiff(props) {
style={{ marginRight: 0 }}
/>
{isVisible &&
(props.commit.document.type === 'mdast' ? (
<Query query={TREE_DIFF_QUERY} variables={variables}>
{({ loading, error, data }) => (
<Overlay
onClose={handleOnClose}
mUpStyle={{ maxWidth: '95vw', minHeight: 'none' }}
>
<OverlayToolbar
title={props.commit.message}
onClose={handleOnClose}
/>
<OverlayBody style={{ fontSize: 13 }}>
<Loader
loading={loading}
error={error}
render={() => (
<ReactDiffViewer
newValue={data.repo.commit.markdown}
styles={newStyles}
splitView={false}
oldValue={data.repo.parentCommit.markdown}
compareMethod={DiffMethod.WORDS_WITH_SPACE}
extraLinesSurroundingDiff={1}
codeFoldMessageRenderer={() => <MdMoreHoriz />}
/>
<Query query={DIFF_QUERY} variables={variables}>
{({ loading, error, data }) => (
<Overlay
onClose={handleOnClose}
mUpStyle={{ maxWidth: '95vw', minHeight: 'none' }}
>
<OverlayToolbar
title={props.commit.message}
onClose={handleOnClose}
/>
<OverlayBody style={{ fontSize: 13 }}>
<Loader
loading={loading}
error={error}
render={() => (
<ReactDiffViewer
newValue={JSON.stringify(
data.repo.commit.document.content,
null,
2,
)}
/>
</OverlayBody>
</Overlay>
)}
</Query>
) : (
<Query query={SLATE_DIFF_QUERY} variables={variables}>
{({ loading, error, data }) => (
<Overlay
onClose={handleOnClose}
mUpStyle={{ maxWidth: '95vw', minHeight: 'none' }}
>
<OverlayToolbar
title={props.commit.message}
onClose={handleOnClose}
/>
<OverlayBody style={{ fontSize: 13 }}>
<Loader
loading={loading}
error={error}
render={() => (
<ReactDiffViewer
newValue={JSON.stringify(
data.repo.commit.document.content,
null,
2,
)}
styles={newStyles}
splitView={false}
oldValue={JSON.stringify(
data.repo.parentCommit.document.content,
null,
2,
)}
compareMethod={DiffMethod.LINES}
extraLinesSurroundingDiff={1}
codeFoldMessageRenderer={() => <MdMoreHoriz />}
/>
styles={newStyles}
splitView={false}
oldValue={JSON.stringify(
data.repo.parentCommit.document.content,
null,
2,
)}
compareMethod={DiffMethod.LINES}
extraLinesSurroundingDiff={1}
codeFoldMessageRenderer={() => <MdMoreHoriz />}
/>
</OverlayBody>
</Overlay>
)}
</Query>
))}
)}
/>
</OverlayBody>
</Overlay>
)}
</Query>
}
</>
)
}
21 changes: 9 additions & 12 deletions apps/publikator/components/editor/MdastPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { graphql } from '@apollo/client/react/hoc'
import { Value, resetKeyGenerator } from 'slate'
import debounce from 'lodash/debounce'
import { timeFormat } from 'd3-time-format'
import { parse, stringify } from '@republik/remark-preset'
import { css } from 'glamor'

import Frame from '../Frame'
Expand Down Expand Up @@ -54,7 +53,7 @@ import createDebug from 'debug'
import {
findAuthorsP,
findTitleLeaf,
generateAuthorsLine,
generateAuthorsMdast
} from '../../lib/utils/helpers'
import { withEditRepoMeta } from '../Repo/EditMetaDate'
import { getRepoIdFromQuery } from '../../lib/repoIdHelper'
Expand Down Expand Up @@ -187,7 +186,9 @@ export class EditorPage extends Component {
}
}
this.lockHandler = (event) => {
event && event.preventDefault()
if (event) {
event.preventDefault()
}
this.setState({
didUnlock: false,
})
Expand All @@ -201,7 +202,7 @@ export class EditorPage extends Component {
this.setState(this.lock)
}
this.unlockHandler = (event) => {
event && event.preventDefault()
if (event) event.preventDefault()
const { t } = this.props

const { activeUsers } = this.state
Expand Down Expand Up @@ -496,8 +497,7 @@ export class EditorPage extends Component {
}
let authorsP = findAuthorsP(json)
if (authorsP) {
const authorsMdast = parse(generateAuthorsLine(this.props.me))
.children[0]
const authorsMdast = generateAuthorsMdast(this.props.me)
authorsP.children = authorsMdast.children
authorsP.type = authorsMdast.type
delete authorsP.value
Expand Down Expand Up @@ -632,6 +632,7 @@ export class EditorPage extends Component {
'loadState',
'documentChangeHandler',
'diff',
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('diff').createPatch(
'string',
JSON.stringify(JSON.parse(committedRawDocString), null, 2),
Expand Down Expand Up @@ -700,12 +701,8 @@ export class EditorPage extends Component {
isTemplate: isNew ? isTemplate === 'true' : data?.repo?.isTemplate,
message: message,
document: {
content: parse(
stringify(
JSON.parse(
JSON.stringify(this.editor.serializer.serialize(editorState)),
),
),
content: JSON.parse(
JSON.stringify(this.editor.serializer.serialize(editorState)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, why are we still stringify-parsing here? Doesn't serialize give us an mdast already?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is just to make a deep copy. we are stringify-parsing to JSON, not markdown. but i understand that it offends you and we should find a more transparent solution.

Copy link
Contributor

Choose a reason for hiding this comment

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

But do we even need to make a copy here? It's just used as an argument for the mutation …

Copy link
Contributor

Choose a reason for hiding this comment

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

The only reason that I can think of why this could be necessary is if serialize() doesn't return a plain JSON object?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is dangerous to ask oneself this kind of questions, Jeremy. (Aka: not sure why it's here, perhaps it's just a remnant from the markdown stringify-parsing – I'll investigate.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think it was because stringifying to markdown was not playing nice with slate, so we needed to execute that operation on a copy of the editor state... so you are probably right, we don't need it. Will try.

),
},
})
Expand Down
12 changes: 5 additions & 7 deletions apps/publikator/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { css } from 'glamor'

import Loader from '../Loader'

import createDocumentModule from './modules/document'
import createDocumentPlainModule from './modules/document/plain'
import createCoverModule from './modules/cover'
import createCenterModule from './modules/center'
Expand Down Expand Up @@ -60,7 +59,6 @@ const moduleCreators = {
embedTwitter: createEmbedTwitterModule,
embedComment: createEmbedCommentModule,
embedDatawrapper: createEmbedDatawrapperModule,
document: createDocumentModule,
documentPlain: createDocumentPlainModule,
cover: createCoverModule,
center: createCenterModule,
Expand Down Expand Up @@ -116,18 +114,18 @@ const initModule = (rule, context = {}) => {
const subModules = (rule.rules || [])
.map((r) => initModule(r, context))
.filter(Boolean)
const module = create({
const ruleModule = create({
TYPE,
rule,
subModules: subModules,
context,
})

module.TYPE = TYPE
module.name = editorModule
module.subModules = subModules
ruleModule.TYPE = TYPE
ruleModule.name = editorModule
ruleModule.subModules = subModules

return module
return ruleModule
}
}
const getAllModules = (module) =>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default (centerModule, figureModule) => (event, change, editor) => {
const isCenter = hasParent(centerModule.TYPE, editor.value.document, cursor)
const isCaption = blockType === 'CAPTION_TEXT'

// TODO: get rid of the markdown step
const toMd = unified()
.use(htmlParse, {
emitParseErrors: true,
Expand Down
Loading
Loading