Skip to content

Please allow a non-diff usage #150

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

Open
AloisMahdal opened this issue Aug 19, 2024 · 5 comments
Open

Please allow a non-diff usage #150

AloisMahdal opened this issue Aug 19, 2024 · 5 comments

Comments

@AloisMahdal
Copy link

Currently we can show diff of two files, but it would be useful to also be able to show a single file.

I know it can be done with highlight.js but in my use case I'm showing diffs as well as whole files on the same page and it would be much easier to manage consistent styling and behavior if I could just use v-code-diff for both. (I think vue-json-compare can do it but it's for Vue 2).

Note that providing two identical texts leads to almost-perfect result for me, except that there are still two columns of line numbers, which would be confusing to user. So what I would like to see is basically the same but with only single column of line numbers.

How would I expect v-code-diff API to change? I'm thinking of several ways

  • make one text optional and switch to single-file mode when it's missing
  • switch to single-file mode if both texts are identical (no change in API)
  • add single-file as a separate display mode (along with side-by-side, etc.)
@Shimada666
Copy link
Owner

Thanks for your suggestion! I need to consider about this.

@AloisMahdal
Copy link
Author

I learned a bit more about Vue and came up with this workaround:

<template>
    <CodeDiff
      hide-header
      language="json"
      :old-string="props.text"
      :new-string="props.text"
    />
</template>

<script setup>
import { CodeDiff } from 'v-code-diff'

const props = defineProps({
  text: {
    type: String,
    required: true,
  },
})
</script>

<style scoped>
.code-diff-view :deep(td:nth-child(1)) {
  display: none;
}
</style>

I saved this as RawJSON.vue and can use it to display nicely formatted JSON by using it as <RawJSON text='{"foo": 1}'/>

@Shimada666
Copy link
Owner

@AloisMahdal
Thank you for your contribution! For now, I have implemented your solution and created the CodeReader component, which is compatible with Vue 2.7 and Vue 3. I will continue to improve it in the future.

@AloisMahdal
Copy link
Author

AloisMahdal commented Dec 13, 2024

Sorry for such a late reply. Thank you for your help!

Unfortunately I don't work with Vue (and probably won't for a while now) now so can't confirm if CodeReader works for me, but it looks good.

Thanks again for working on this!

@Shimada666
Copy link
Owner

No problem at all! Feel free to reach out if you need help with anything else in the future!

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