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

Request: Option to give id attribute to lines #107

Open
GeorgeWL opened this issue Dec 4, 2020 · 1 comment
Open

Request: Option to give id attribute to lines #107

GeorgeWL opened this issue Dec 4, 2020 · 1 comment

Comments

@GeorgeWL
Copy link

GeorgeWL commented Dec 4, 2020

I've been wanting to have it copy the behaviour of github in that on line click, it adds the hash of #line57 to the end of the url, and that if someone then loads that url, it jumps to that position in the page

To make that easier it would be good if renderContent or some other prop could allow one to set the line numbers as the id of the <tr>

e.g.:

const newContent = (renderProps) =><tr id={renderProps.lineId}>{renderProps.children}</tr>

or even simpler, just something like a

...
withIdAttrib={true}
/>
@bramses
Copy link

bramses commented Oct 16, 2021

pretty easy local fix:

private renderSplitView = (

change:

private renderSplitView = (
		{ left, right }: LineInformation,
		index: number,
	): JSX.Element => {
		return (
			<tr key={index} className={this.styles.line}>
				{this.renderLine(
					left.lineNumber,
					left.type,
					LineNumberPrefix.LEFT,
					left.value,
				)}
				{this.renderLine(
					right.lineNumber,
					right.type,
					LineNumberPrefix.RIGHT,
					right.value,
				)}
			</tr>
		);
	};

to:

React.createElement("tr", { id: left.lineNumber, key: index, className: _this.styles.line }

note in your local project this TS will be compiled into JS, my change was on L166 of index.js

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

No branches or pull requests

2 participants