mirror of
https://github.com/github/semantic.git
synced 2024-12-20 05:11:44 +03:00
Merge pull request #1192 from github/md-toc-summary-headings
Markdown toc summary headings
This commit is contained in:
commit
dacfb4c3a0
@ -28,6 +28,7 @@ import Data.Proxy
|
||||
import Data.Record
|
||||
import Data.Source as Source
|
||||
import Data.Text (toLower)
|
||||
import qualified Data.Text as T
|
||||
import Data.Text.Listable
|
||||
import Data.These
|
||||
import Data.Union
|
||||
@ -213,7 +214,7 @@ toCategoryName :: Declaration -> Text
|
||||
toCategoryName declaration = case declaration of
|
||||
FunctionDeclaration _ -> "Function"
|
||||
MethodDeclaration _ -> "Method"
|
||||
SectionDeclaration _ -> "Section"
|
||||
SectionDeclaration x -> "Heading " <> show (T.length (T.takeWhile (== '#') x))
|
||||
ErrorDeclaration _ -> "ParseError"
|
||||
|
||||
instance Listable Declaration where
|
||||
|
@ -149,6 +149,12 @@ spec = parallel $ do
|
||||
output <- runTask (diffBlobPair ToCDiffRenderer blobs)
|
||||
toS output `shouldBe` ("{\"changes\":{\"test/fixtures/toc/ruby/methods.A.rb -> test/fixtures/toc/ruby/methods.X.rb\":[{\"span\":{\"start\":[4,1],\"end\":[5,4]},\"category\":\"Method\",\"term\":\"baz\",\"changeType\":\"removed\"}]},\"errors\":{\"test/fixtures/toc/ruby/methods.A.rb -> test/fixtures/toc/ruby/methods.X.rb\":[{\"span\":{\"start\":[1,1],\"end\":[3,1]},\"error\":\"def bar\\nen\\n\"}]}}\n" :: ByteString)
|
||||
|
||||
it "summarizes Markdown headings" $ do
|
||||
blobs <- blobsForPaths (both "markdown/headings.A.md" "markdown/headings.B.md")
|
||||
output <- runTask (diffBlobPair ToCDiffRenderer blobs)
|
||||
toS output `shouldBe` ("{\"changes\":{\"test/fixtures/toc/markdown/headings.A.md -> test/fixtures/toc/markdown/headings.B.md\":[{\"span\":{\"start\":[5,1],\"end\":[5,7]},\"category\":\"Heading 2\",\"term\":\"## Two\",\"changeType\":\"added\"}]},\"errors\":{}}\n" :: ByteString)
|
||||
|
||||
|
||||
type Diff' = SyntaxDiff Text (Maybe Declaration ': DefaultFields)
|
||||
type Term' = SyntaxTerm Text (Maybe Declaration ': DefaultFields)
|
||||
|
||||
|
3
test/fixtures/toc/markdown/headings.A.md
vendored
Normal file
3
test/fixtures/toc/markdown/headings.A.md
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# One
|
||||
|
||||
Just some text
|
5
test/fixtures/toc/markdown/headings.B.md
vendored
Normal file
5
test/fixtures/toc/markdown/headings.B.md
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
# One
|
||||
|
||||
Just some text
|
||||
|
||||
## Two
|
Loading…
Reference in New Issue
Block a user