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

Resolve relative URLs in markdown cells to notebook directory #1432

Closed
wants to merge 2 commits into from

Conversation

gnestor
Copy link
Contributor

@gnestor gnestor commented Feb 7, 2017

Follow up from #349

To do:

Copy link
Member

@rgbkrk rgbkrk 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 so good to see the commonmark parser being used really well!

const { node } = event;
if (event.entering && node.type === 'link') {
node.destination = url.resolve(cwd, node.destination);
}
Copy link
Member

Choose a reason for hiding this comment

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

Neat!

@@ -123,6 +118,23 @@ export default class MarkdownCell extends React.PureComponent {
}

render(): ?React.Element<any> {
const { filename } = this.context.store.getState().metadata.toJS();
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't be relying on this.context in these components. Perhaps we could pass down what the cwd is?

Copy link
Member

Choose a reason for hiding this comment

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

As in from a top level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ya, I couldn't figure out how to access it otherwise. Your <base> idea sounds better if I understand it correctly: it's a component that has access to cwd among other things and it passes it down to other components via props.

Copy link
Member

@rgbkrk rgbkrk Feb 8, 2017

Choose a reason for hiding this comment

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

<base> is an HTML Element that specifies the base URL to use for all relative URLs in a document, it's not a React component. With the power of React though, when the filename changes, so would base's href and thereby the interpretation of all relative paths.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohhhh! Ya, that's perfect except that it messes up relative URLs to nteract assets 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I was thinking that since we're doing webpack anyways we could make sure the base assets are loaded first. The ones that are gunked up in the little prototype I showed was only the theme css (which can change).

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 just pushed another commit that breaks the context stuff out into a Base component. I did this yesterday before I realized that <base> is an HTML element, so for what it's worth...

Copy link
Member

Choose a reason for hiding this comment

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

You had me a bit worried when I saw the commit before your comment.

The component you've added Base into is supposed to be a disconnected component, in line with #1288.

@rgbkrk
Copy link
Member

rgbkrk commented Feb 8, 2017

Great to see this solution! This component is supposed to be a presentational component and as such should not have access to context - props are intended to be the only API in accordance with #1288. I'd like to solve this either with the <base> (and required loading changes) or by passing the cwd down through the entire tree (yes, that would be a lot of boilerplate to pass it through).

The other issue with relying on context for this is that it will not necessarily re-render when the filename changes as opposed to when its a prop.

@gnestor
Copy link
Contributor Author

gnestor commented Feb 8, 2017

This component is supposed to be a presentational component and as such should not have access to context

I get that, but why does MarkdownCell and others define contextTypes then?

I'd like to solve this either with the

This is ideal.

@rgbkrk
Copy link
Member

rgbkrk commented Feb 8, 2017

I get that, but why does MarkdownCell and others define contextTypes then?

The cell components are currently open check boxes on that issue. I'd rather not introduce more to refactor when we have other options for doing this in line with the architecture plan.

@gnestor
Copy link
Contributor Author

gnestor commented Feb 8, 2017

Ok I see. Props-only approach is vastly superior 👍

@rgbkrk rgbkrk mentioned this pull request Mar 16, 2017
@rgbkrk
Copy link
Member

rgbkrk commented Mar 21, 2017

From direct messages, I'd love to see this done with <base> so that MarkdownCell can be used without knowledge of cwd. It should work like any other relative notebook asset.

@rgbkrk
Copy link
Member

rgbkrk commented Mar 21, 2017

#349 (comment)

@rgbkrk
Copy link
Member

rgbkrk commented Aug 15, 2017

Closing in favor of #1720.

@rgbkrk rgbkrk closed this Aug 15, 2017
@lock
Copy link

lock bot commented Apr 2, 2018

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked and limited conversation to collaborators Apr 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants